From c38488dfc47f1c9c9472db0bc2ea6844bd8e5b5f Mon Sep 17 00:00:00 2001 From: Balu Babu Date: Fri, 21 Jul 2023 16:05:27 +0530 Subject: [PATCH] feat: magic-link can now be conditionally provisioned --- .env.example | 1 + packages/hoppscotch-backend/src/auth/auth.controller.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index ddcf09a35..fe0d68c00 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,7 @@ SESSION_SECRET='add some secret here' # Hoppscotch App Domain Config REDIRECT_URL="http://localhost:3000" WHITELISTED_ORIGINS = "http://localhost:3170,http://localhost:3000,http://localhost:3100" +ALLOWED_AUTH_PROVIDERS = GOOGLE,GITHUB,MICROSOFT,EMAIL # Google Auth Config GOOGLE_CLIENT_ID="************************************************" diff --git a/packages/hoppscotch-backend/src/auth/auth.controller.ts b/packages/hoppscotch-backend/src/auth/auth.controller.ts index dba497161..1f7fd35b5 100644 --- a/packages/hoppscotch-backend/src/auth/auth.controller.ts +++ b/packages/hoppscotch-backend/src/auth/auth.controller.ts @@ -2,11 +2,13 @@ import { Body, Controller, Get, + InternalServerErrorException, Post, Query, Req, Request, Res, + UnauthorizedException, UseGuards, } from '@nestjs/common'; import { AuthService } from './auth.service'; @@ -19,7 +21,7 @@ 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, throwHTTPErr } from './helper'; +import { 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,6 +41,7 @@ export class AuthController { @Body() authData: SignInMagicDto, @Query('origin') origin: string, ) { + if (!authProviderCheck('EMAIL')) throw new InternalServerErrorException(); const deviceIdToken = await this.authService.signInMagicLink( authData.email, origin,