chore: auth provider name read from enum

This commit is contained in:
Mir Arif Hasan
2023-07-28 18:25:45 +06:00
committed by Andrew Bastin
parent d3f25361f7
commit 092cb4c3a5
3 changed files with 20 additions and 6 deletions

View File

@@ -19,7 +19,12 @@ import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { GqlUser } from 'src/decorators/gql-user.decorator'; import { GqlUser } from 'src/decorators/gql-user.decorator';
import { AuthUser } from 'src/types/AuthUser'; import { AuthUser } from 'src/types/AuthUser';
import { RTCookie } from 'src/decorators/rt-cookie.decorator'; import { RTCookie } from 'src/decorators/rt-cookie.decorator';
import { authCookieHandler, authProviderCheck, throwHTTPErr } from './helper'; import {
AuthProvider,
authCookieHandler,
authProviderCheck,
throwHTTPErr,
} from './helper';
import { GoogleSSOGuard } from './guards/google-sso.guard'; import { GoogleSSOGuard } from './guards/google-sso.guard';
import { GithubSSOGuard } from './guards/github-sso.guard'; import { GithubSSOGuard } from './guards/github-sso.guard';
import { MicrosoftSSOGuard } from './guards/microsoft-sso-.guard'; import { MicrosoftSSOGuard } from './guards/microsoft-sso-.guard';
@@ -39,7 +44,9 @@ export class AuthController {
@Body() authData: SignInMagicDto, @Body() authData: SignInMagicDto,
@Query('origin') origin: string, @Query('origin') origin: string,
) { ) {
if (!authProviderCheck('EMAIL')) throw new InternalServerErrorException(); if (!authProviderCheck(AuthProvider.EMAIL))
throw new InternalServerErrorException();
const deviceIdToken = await this.authService.signInMagicLink( const deviceIdToken = await this.authService.signInMagicLink(
authData.email, authData.email,
origin, origin,

View File

@@ -11,7 +11,7 @@ import { RTJwtStrategy } from './strategies/rt-jwt.strategy';
import { GoogleStrategy } from './strategies/google.strategy'; import { GoogleStrategy } from './strategies/google.strategy';
import { GithubStrategy } from './strategies/github.strategy'; import { GithubStrategy } from './strategies/github.strategy';
import { MicrosoftStrategy } from './strategies/microsoft.strategy'; import { MicrosoftStrategy } from './strategies/microsoft.strategy';
import { authProviderCheck } from './helper'; import { AuthProvider, authProviderCheck } from './helper';
@Module({ @Module({
imports: [ imports: [
@@ -27,9 +27,9 @@ import { authProviderCheck } from './helper';
AuthService, AuthService,
JwtStrategy, JwtStrategy,
RTJwtStrategy, RTJwtStrategy,
...(authProviderCheck('GOOGLE') ? [GoogleStrategy] : []), ...(authProviderCheck(AuthProvider.GOOGLE) ? [GoogleStrategy] : []),
...(authProviderCheck('GITHUB') ? [GithubStrategy] : []), ...(authProviderCheck(AuthProvider.GITHUB) ? [GithubStrategy] : []),
...(authProviderCheck('MICROSOFT') ? [MicrosoftStrategy] : []), ...(authProviderCheck(AuthProvider.MICROSOFT) ? [MicrosoftStrategy] : []),
], ],
controllers: [AuthController], controllers: [AuthController],
}) })

View File

@@ -17,6 +17,13 @@ export enum Origin {
APP = 'app', APP = 'app',
} }
export enum AuthProvider {
GOOGLE = 'GOOGLE',
GITHUB = 'GITHUB',
MICROSOFT = 'MICROSOFT',
EMAIL = 'EMAIL',
}
/** /**
* This function allows throw to be used as an expression * This function allows throw to be used as an expression
* @param errMessage Message present in the error message * @param errMessage Message present in the error message