From 9408ba7f3487f7c97984c05e3769324c369accef Mon Sep 17 00:00:00 2001 From: GloireMutaliko21 Date: Tue, 18 Jun 2024 16:05:16 +0200 Subject: [PATCH 1/2] refact: oauth configs using consistent naming --- apps/web/app/constants.ts | 29 +++++++++ .../web/app/services/server/requests/OAuth.ts | 2 +- apps/web/app/utils/check-provider-env-vars.ts | 65 ++++++++++++++++--- 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/apps/web/app/constants.ts b/apps/web/app/constants.ts index 879899334..bc7dd312e 100644 --- a/apps/web/app/constants.ts +++ b/apps/web/app/constants.ts @@ -263,3 +263,32 @@ export const languagesFlags = [ code: 'he' } ]; + +// OAuth providers keys + +export const APPLE_CLIENT_ID = process.env.APPLE_CLIENT_ID; +export const APPLE_CLIENT_SECRET = process.env.APPLE_CLIENT_SECRET; + +export const DISCORD_CLIENT_ID = process.env.DISCORD_CLIENT_ID; +export const DISCORD_CLIENT_SECRET = process.env.DISCORD_CLIENT_SECRET; + +export const FACEBOOK_CLIENT_ID = process.env.FACEBOOK_CLIENT_ID; +export const FACEBOOK_CLIENT_SECRET = process.env.FACEBOOK_CLIENT_SECRET; + +export const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID; +export const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET; + +export const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID; +export const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET; + +export const LINKEDIN_CLIENT_ID = process.env.LINKEDIN_CLIENT_ID; +export const LINKEDIN_CLIENT_SECRET = process.env.LINKEDIN_CLIENT_SECRET; + +export const MICROSOFT_CLIENT_ID = process.env.MICROSOFT_CLIENT_ID; +export const MICROSOFT_CLIENT_SECRET = process.env.MICROSOFT_CLIENT_SECRET; + +export const SLACK_CLIENT_ID = process.env.SLACK_CLIENT_ID; +export const SLACK_CLIENT_SECRET = process.env.SLACK_CLIENT_SECRET; + +export const TWITTER_CLIENT_ID = process.env.TWITTER_CLIENT_ID; +export const TWITTER_CLIENT_SECRET = process.env.TWITTER_CLIENT_SECRET; diff --git a/apps/web/app/services/server/requests/OAuth.ts b/apps/web/app/services/server/requests/OAuth.ts index 25f4cd683..80b05a018 100644 --- a/apps/web/app/services/server/requests/OAuth.ts +++ b/apps/web/app/services/server/requests/OAuth.ts @@ -27,7 +27,6 @@ export enum ProviderEnum { export function GauzyAdapter(req: NextRequest): Adapter { return { createUser: async (user): Promise => { - console.log('=========================== CREATE'); const url = new URL(req.url); const { email, name } = user; @@ -102,6 +101,7 @@ export function GauzyAdapter(req: NextRequest): Adapter { }, getUserByEmail: async (): Promise => { + console.log('GET BY EMAIL FAILS'); return null; }, diff --git a/apps/web/app/utils/check-provider-env-vars.ts b/apps/web/app/utils/check-provider-env-vars.ts index 5da54f669..b469720e9 100644 --- a/apps/web/app/utils/check-provider-env-vars.ts +++ b/apps/web/app/utils/check-provider-env-vars.ts @@ -8,6 +8,26 @@ import MicrosoftEntraID from '@auth/core/providers/microsoft-entra-id'; import Slack from '@auth/core/providers/slack'; import Twitter from '@auth/core/providers/twitter'; import type { Provider } from '@auth/core/providers'; +import { + APPLE_CLIENT_ID, + APPLE_CLIENT_SECRET, + DISCORD_CLIENT_ID, + DISCORD_CLIENT_SECRET, + FACEBOOK_CLIENT_ID, + FACEBOOK_CLIENT_SECRET, + GITHUB_CLIENT_ID, + GITHUB_CLIENT_SECRET, + GOOGLE_CLIENT_ID, + GOOGLE_CLIENT_SECRET, + LINKEDIN_CLIENT_ID, + LINKEDIN_CLIENT_SECRET, + MICROSOFT_CLIENT_ID, + MICROSOFT_CLIENT_SECRET, + SLACK_CLIENT_ID, + SLACK_CLIENT_SECRET, + TWITTER_CLIENT_ID, + TWITTER_CLIENT_SECRET +} from '@app/constants'; type ProviderNames = { [key: string]: string | undefined; @@ -26,15 +46,42 @@ export const providerNames: ProviderNames = { }; export const providers: Provider[] = [ - Apple, - Discord, - Facebook, - Google, - Github, - Linkedin, - MicrosoftEntraID, - Slack, - Twitter + Apple({ + clientId: APPLE_CLIENT_ID, + clientSecret: APPLE_CLIENT_SECRET || '' + }), + Discord({ + clientId: DISCORD_CLIENT_ID, + clientSecret: DISCORD_CLIENT_SECRET + }), + Facebook({ + clientId: FACEBOOK_CLIENT_ID, + clientSecret: FACEBOOK_CLIENT_SECRET + }), + Google({ + clientId: GOOGLE_CLIENT_ID, + clientSecret: GOOGLE_CLIENT_SECRET + }), + Github({ + clientId: GITHUB_CLIENT_ID, + clientSecret: GITHUB_CLIENT_SECRET + }), + Linkedin({ + clientId: LINKEDIN_CLIENT_ID, + clientSecret: LINKEDIN_CLIENT_SECRET + }), + MicrosoftEntraID({ + clientId: MICROSOFT_CLIENT_ID, + clientSecret: MICROSOFT_CLIENT_SECRET + }), + Slack({ + clientId: SLACK_CLIENT_ID, + clientSecret: SLACK_CLIENT_SECRET + }), + Twitter({ + clientId: TWITTER_CLIENT_ID, + clientSecret: TWITTER_CLIENT_SECRET + }) ]; export const filteredProviders = providers.filter((provider) => { From ec5c4043aafd866d64079a5bd0ce17a12f1e5dde Mon Sep 17 00:00:00 2001 From: GloireMutaliko21 Date: Tue, 18 Jun 2024 16:10:45 +0200 Subject: [PATCH 2/2] fix: remove unnecessarily logs --- apps/web/app/services/server/requests/OAuth.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/app/services/server/requests/OAuth.ts b/apps/web/app/services/server/requests/OAuth.ts index 80b05a018..fb92a0e41 100644 --- a/apps/web/app/services/server/requests/OAuth.ts +++ b/apps/web/app/services/server/requests/OAuth.ts @@ -101,7 +101,6 @@ export function GauzyAdapter(req: NextRequest): Adapter { }, getUserByEmail: async (): Promise => { - console.log('GET BY EMAIL FAILS'); return null; },