From 13ba6caa4acbb97c4a5f19f2efc6729247a9a434 Mon Sep 17 00:00:00 2001 From: "mike.toggweiler" Date: Wed, 29 Jan 2025 16:20:47 +0100 Subject: [PATCH] read OAUTH_ENABLED flag server side as client side env vars are resolved at build time only --- .env.example | 2 +- README.md | 2 +- payload.config.ts | 4 +- src/app/(payload)/admin/importMap.js | 6 +- ...tton.tsx => oauth-client-login-button.tsx} | 9 ++- .../components/oauth-server-login-button.tsx | 9 +++ src/types/payload-types.ts | 74 +++++++++---------- 7 files changed, 60 insertions(+), 46 deletions(-) rename src/payload/components/{oauth-login-button.tsx => oauth-client-login-button.tsx} (70%) create mode 100644 src/payload/components/oauth-server-login-button.tsx diff --git a/.env.example b/.env.example index 83bed5a..df19dfe 100644 --- a/.env.example +++ b/.env.example @@ -39,7 +39,7 @@ PUBLIC_URL=http://localhost:3000 # LOCAL_MEDIA_STORAGE_DIR=/data/media # Uncomment if you want to configure an integration to an oauth client -# NEXT_PUBLIC_OAUTH_ENABLE=true +# OAUTH_ENABLED=true # OAUTH_CLIENT_ID=secret # OAUTH_CLIENT_SECRET=secret # OAUTH_TOKEN_ENDPOINT=http://localhost:8080/oauth/token diff --git a/README.md b/README.md index 342af74..ae77462 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The following databases are supported by the cv-manager: The cv-manager support OAuth integration. To enable the oauth integration, provide the following configuration properties: -- `NEXT_PUBLIC_OAUTH_ENABLE=true` +- `OAUTH_ENABLED=true` - `OAUTH_CLIENT_ID` - `OAUTH_CLIENT_SECRET` - `OAUTH_TOKEN_ENDPOINT` diff --git a/payload.config.ts b/payload.config.ts index 0fdea94..65bd5b1 100644 --- a/payload.config.ts +++ b/payload.config.ts @@ -114,7 +114,7 @@ export default buildConfig({ : {}), user: Users.slug, components: { - afterLogin: ['src/payload/components/oauth-login-button#OAuthLoginButton'], + afterLogin: ['src/payload/components/oauth-server-login-button#OAuthServerLoginButton'], graphics: { // shown in the nav bar Icon: 'src/graphics/Icon/index.tsx#Icon', @@ -190,7 +190,7 @@ export default buildConfig({ OAuth2Plugin({ strategyName: 'oauth2', useEmailAsIdentity: false, - enabled: process.env.NEXT_PUBLIC_OAUTH_ENABLE == 'true' || false, + enabled: process.env.OAUTH_ENABLED === 'true' || false, serverURL: process.env.PUBLIC_URL || 'http://localhost:3000', authCollection: Users.slug, clientId: process.env.OAUTH_CLIENT_ID || '', diff --git a/src/app/(payload)/admin/importMap.js b/src/app/(payload)/admin/importMap.js index 09fa9e4..3851818 100644 --- a/src/app/(payload)/admin/importMap.js +++ b/src/app/(payload)/admin/importMap.js @@ -27,7 +27,7 @@ import { RowLabelFirstText as RowLabelFirstText_3c155042d49e8cad65cddd438f13227f import { SaveButtonReplacer as SaveButtonReplacer_abe15da8360ef82ce201907c427c7d1a } from '/src/payload/plugins/cv-pdf-generator/ui/saveButtonReplacer.tsx'; import { Icon as Icon_c91f387b1e1e266abbd316576a738bc6 } from 'src/graphics/Icon/index.tsx'; import { Logo as Logo_0c05d89cc4c8a8bbbb6822cd8c3420f3 } from 'src/graphics/Logo/index.tsx'; -import { OAuthLoginButton as OAuthLoginButton_53e01bf128a2abcbd4dac91e546cd542 } from 'src/payload/components/oauth-login-button'; +import { OAuthServerLoginButton as OAuthServerLoginButton_b203fbaee741012621fc45713338946f } from 'src/payload/components/oauth-server-login-button'; export const importMap = { '@payloadcms/richtext-lexical/rsc#RscEntryLexicalCell': @@ -86,6 +86,6 @@ export const importMap = { SaveButtonReplacer_abe15da8360ef82ce201907c427c7d1a, 'src/graphics/Icon/index.tsx#Icon': Icon_c91f387b1e1e266abbd316576a738bc6, 'src/graphics/Logo/index.tsx#Logo': Logo_0c05d89cc4c8a8bbbb6822cd8c3420f3, - 'src/payload/components/oauth-login-button#OAuthLoginButton': - OAuthLoginButton_53e01bf128a2abcbd4dac91e546cd542, + 'src/payload/components/oauth-server-login-button#OAuthServerLoginButton': + OAuthServerLoginButton_b203fbaee741012621fc45713338946f, }; diff --git a/src/payload/components/oauth-login-button.tsx b/src/payload/components/oauth-client-login-button.tsx similarity index 70% rename from src/payload/components/oauth-login-button.tsx rename to src/payload/components/oauth-client-login-button.tsx index 248b6ac..2f8dba6 100644 --- a/src/payload/components/oauth-login-button.tsx +++ b/src/payload/components/oauth-client-login-button.tsx @@ -1,7 +1,12 @@ 'use client'; -export const OAuthLoginButton: React.FC = () => ( + +type ClientButtonProps = { + oauthEnabled: Boolean; +}; + +export const OAuthClientLoginButton: React.FC = ({ oauthEnabled }) => ( <> - {process.env.NEXT_PUBLIC_OAUTH_ENABLE == 'true' && ( + {oauthEnabled && (