Skip to content

Commit

Permalink
feat: add github auth env validation
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-w committed Mar 13, 2024
1 parent 3b75be7 commit 988786f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions apps/nestjs-backend/src/configs/env.validation.schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import Joi from 'joi';

export const envValidationSchema = Joi.object({
Expand Down Expand Up @@ -37,4 +38,23 @@ export const envValidationSchema = Joi.object({
.pattern(/^(redis:\/\/|rediss:\/\/)/)
.message('Cache `redis` the URI must start with the protocol `redis://` or `rediss://`'),
}),
// github auth
BACKEND_GITHUB_CLIENT_ID: Joi.when('SOCIAL_AUTH_PROVIDERS', {
is: Joi.string()
.regex(/(^|,)(github)(,|$)/)
.required(),
then: Joi.string().required().messages({
'any.required':
'The `BACKEND_GITHUB_CLIENT_ID` is required when `SOCIAL_AUTH_PROVIDERS` includes `github`',
}),
}),
BACKEND_GITHUB_CLIENT_SECRET: Joi.when('SOCIAL_AUTH_PROVIDERS', {
is: Joi.string()
.regex(/(^|,)(github)(,|$)/)
.required(),
then: Joi.string().required().messages({
'any.required':
'The `BACKEND_GITHUB_CLIENT_SECRET` is required when `SOCIAL_AUTH_PROVIDERS` includes `github`',
}),
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GithubModule } from './github/github.module';
@Module({
imports: [
ConditionalModule.registerWhen(GithubModule, (env) => {
return Boolean(env.SOCIAL_AUTH_PROVIDERS?.includes('github'));
return Boolean(env.SOCIAL_AUTH_PROVIDERS?.split(',')?.includes('github'));
}),
],
})
Expand Down

0 comments on commit 988786f

Please sign in to comment.