diff --git a/packages/hoppscotch-backend/src/auth/auth.controller.ts b/packages/hoppscotch-backend/src/auth/auth.controller.ts index 32cec7878..b09aff9d6 100644 --- a/packages/hoppscotch-backend/src/auth/auth.controller.ts +++ b/packages/hoppscotch-backend/src/auth/auth.controller.ts @@ -19,7 +19,12 @@ import { JwtAuthGuard } from './guards/jwt-auth.guard'; import { GqlUser } from 'src/decorators/gql-user.decorator'; import { AuthUser } from 'src/types/AuthUser'; 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 { GithubSSOGuard } from './guards/github-sso.guard'; import { MicrosoftSSOGuard } from './guards/microsoft-sso-.guard'; @@ -39,7 +44,9 @@ export class AuthController { @Body() authData: SignInMagicDto, @Query('origin') origin: string, ) { - if (!authProviderCheck('EMAIL')) throw new InternalServerErrorException(); + if (!authProviderCheck(AuthProvider.EMAIL)) + throw new InternalServerErrorException(); + const deviceIdToken = await this.authService.signInMagicLink( authData.email, origin, diff --git a/packages/hoppscotch-backend/src/auth/auth.module.ts b/packages/hoppscotch-backend/src/auth/auth.module.ts index e00917616..2c79e6250 100644 --- a/packages/hoppscotch-backend/src/auth/auth.module.ts +++ b/packages/hoppscotch-backend/src/auth/auth.module.ts @@ -11,7 +11,7 @@ import { RTJwtStrategy } from './strategies/rt-jwt.strategy'; import { GoogleStrategy } from './strategies/google.strategy'; import { GithubStrategy } from './strategies/github.strategy'; import { MicrosoftStrategy } from './strategies/microsoft.strategy'; -import { authProviderCheck } from './helper'; +import { AuthProvider, authProviderCheck } from './helper'; @Module({ imports: [ @@ -27,9 +27,9 @@ import { authProviderCheck } from './helper'; AuthService, JwtStrategy, RTJwtStrategy, - ...(authProviderCheck('GOOGLE') ? [GoogleStrategy] : []), - ...(authProviderCheck('GITHUB') ? [GithubStrategy] : []), - ...(authProviderCheck('MICROSOFT') ? [MicrosoftStrategy] : []), + ...(authProviderCheck(AuthProvider.GOOGLE) ? [GoogleStrategy] : []), + ...(authProviderCheck(AuthProvider.GITHUB) ? [GithubStrategy] : []), + ...(authProviderCheck(AuthProvider.MICROSOFT) ? [MicrosoftStrategy] : []), ], controllers: [AuthController], }) diff --git a/packages/hoppscotch-backend/src/auth/helper.ts b/packages/hoppscotch-backend/src/auth/helper.ts index b3e7cbdea..35cf55d62 100644 --- a/packages/hoppscotch-backend/src/auth/helper.ts +++ b/packages/hoppscotch-backend/src/auth/helper.ts @@ -17,6 +17,13 @@ export enum Origin { APP = 'app', } +export enum AuthProvider { + GOOGLE = 'GOOGLE', + GITHUB = 'GITHUB', + MICROSOFT = 'MICROSOFT', + EMAIL = 'EMAIL', +} + /** * This function allows throw to be used as an expression * @param errMessage Message present in the error message