Skip to content

Commit 13ba6ca

Browse files
committed
read OAUTH_ENABLED flag server side as client side env vars are resolved at build time only
1 parent 9860629 commit 13ba6ca

File tree

7 files changed

+60
-46
lines changed

7 files changed

+60
-46
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PUBLIC_URL=http://localhost:3000
3939
# LOCAL_MEDIA_STORAGE_DIR=/data/media
4040

4141
# Uncomment if you want to configure an integration to an oauth client
42-
# NEXT_PUBLIC_OAUTH_ENABLE=true
42+
# OAUTH_ENABLED=true
4343
# OAUTH_CLIENT_ID=secret
4444
# OAUTH_CLIENT_SECRET=secret
4545
# OAUTH_TOKEN_ENDPOINT=http://localhost:8080/oauth/token

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The following databases are supported by the cv-manager:
4242

4343
The cv-manager support OAuth integration. To enable the oauth integration, provide the following configuration properties:
4444

45-
- `NEXT_PUBLIC_OAUTH_ENABLE=true`
45+
- `OAUTH_ENABLED=true`
4646
- `OAUTH_CLIENT_ID`
4747
- `OAUTH_CLIENT_SECRET`
4848
- `OAUTH_TOKEN_ENDPOINT`

payload.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default buildConfig({
114114
: {}),
115115
user: Users.slug,
116116
components: {
117-
afterLogin: ['src/payload/components/oauth-login-button#OAuthLoginButton'],
117+
afterLogin: ['src/payload/components/oauth-server-login-button#OAuthServerLoginButton'],
118118
graphics: {
119119
// shown in the nav bar
120120
Icon: 'src/graphics/Icon/index.tsx#Icon',
@@ -190,7 +190,7 @@ export default buildConfig({
190190
OAuth2Plugin({
191191
strategyName: 'oauth2',
192192
useEmailAsIdentity: false,
193-
enabled: process.env.NEXT_PUBLIC_OAUTH_ENABLE == 'true' || false,
193+
enabled: process.env.OAUTH_ENABLED === 'true' || false,
194194
serverURL: process.env.PUBLIC_URL || 'http://localhost:3000',
195195
authCollection: Users.slug,
196196
clientId: process.env.OAUTH_CLIENT_ID || '',

src/app/(payload)/admin/importMap.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { RowLabelFirstText as RowLabelFirstText_3c155042d49e8cad65cddd438f13227f
2727
import { SaveButtonReplacer as SaveButtonReplacer_abe15da8360ef82ce201907c427c7d1a } from '/src/payload/plugins/cv-pdf-generator/ui/saveButtonReplacer.tsx';
2828
import { Icon as Icon_c91f387b1e1e266abbd316576a738bc6 } from 'src/graphics/Icon/index.tsx';
2929
import { Logo as Logo_0c05d89cc4c8a8bbbb6822cd8c3420f3 } from 'src/graphics/Logo/index.tsx';
30-
import { OAuthLoginButton as OAuthLoginButton_53e01bf128a2abcbd4dac91e546cd542 } from 'src/payload/components/oauth-login-button';
30+
import { OAuthServerLoginButton as OAuthServerLoginButton_b203fbaee741012621fc45713338946f } from 'src/payload/components/oauth-server-login-button';
3131

3232
export const importMap = {
3333
'@payloadcms/richtext-lexical/rsc#RscEntryLexicalCell':
@@ -86,6 +86,6 @@ export const importMap = {
8686
SaveButtonReplacer_abe15da8360ef82ce201907c427c7d1a,
8787
'src/graphics/Icon/index.tsx#Icon': Icon_c91f387b1e1e266abbd316576a738bc6,
8888
'src/graphics/Logo/index.tsx#Logo': Logo_0c05d89cc4c8a8bbbb6822cd8c3420f3,
89-
'src/payload/components/oauth-login-button#OAuthLoginButton':
90-
OAuthLoginButton_53e01bf128a2abcbd4dac91e546cd542,
89+
'src/payload/components/oauth-server-login-button#OAuthServerLoginButton':
90+
OAuthServerLoginButton_b203fbaee741012621fc45713338946f,
9191
};

src/payload/components/oauth-login-button.tsx src/payload/components/oauth-client-login-button.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use client';
2-
export const OAuthLoginButton: React.FC = () => (
2+
3+
type ClientButtonProps = {
4+
oauthEnabled: Boolean;
5+
};
6+
7+
export const OAuthClientLoginButton: React.FC<ClientButtonProps> = ({ oauthEnabled }) => (
38
<>
4-
{process.env.NEXT_PUBLIC_OAUTH_ENABLE == 'true' && (
9+
{oauthEnabled && (
510
<div className={'w-full'}>
611
<button
712
type={'button'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { OAuthClientLoginButton } from './oauth-client-login-button';
3+
4+
export const OAuthServerLoginButton: React.FC = () => {
5+
return (
6+
<OAuthClientLoginButton
7+
oauthEnabled={process.env.OAUTH_ENABLED === 'true'}></OAuthClientLoginButton>
8+
);
9+
};

src/types/payload-types.ts

+37-37
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface Config {
3535
};
3636
collections: {
3737
cv: Cv;
38+
users: User;
3839
skill: Skill;
3940
skillGroup: SkillGroup;
4041
langs: Lang;
@@ -43,14 +44,14 @@ export interface Config {
4344
project: Project;
4445
media: Media;
4546
organisations: Organisation;
46-
users: User;
4747
'payload-locked-documents': PayloadLockedDocument;
4848
'payload-preferences': PayloadPreference;
4949
'payload-migrations': PayloadMigration;
5050
};
5151
collectionsJoins: {};
5252
collectionsSelect: {
5353
cv: CvSelect<false> | CvSelect<true>;
54+
users: UsersSelect<false> | UsersSelect<true>;
5455
skill: SkillSelect<false> | SkillSelect<true>;
5556
skillGroup: SkillGroupSelect<false> | SkillGroupSelect<true>;
5657
langs: LangsSelect<false> | LangsSelect<true>;
@@ -59,7 +60,6 @@ export interface Config {
5960
project: ProjectSelect<false> | ProjectSelect<true>;
6061
media: MediaSelect<false> | MediaSelect<true>;
6162
organisations: OrganisationsSelect<false> | OrganisationsSelect<true>;
62-
users: UsersSelect<false> | UsersSelect<true>;
6363
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
6464
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
6565
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@@ -399,6 +399,7 @@ export interface Media {
399399
organisation?: (number | null) | Organisation;
400400
createdBy?: (number | null) | User;
401401
updatedBy?: (number | null) | User;
402+
prefix?: string | null;
402403
updatedAt: string;
403404
createdAt: string;
404405
url?: string | null;
@@ -461,7 +462,6 @@ export interface User {
461462
roles?: ('admin' | 'user')[] | null;
462463
organisations?: UserOrganisations;
463464
selectedOrganisation?: (number | null) | Organisation;
464-
sub?: string | null;
465465
updatedAt: string;
466466
createdAt: string;
467467
email: string;
@@ -613,6 +613,10 @@ export interface PayloadLockedDocument {
613613
relationTo: 'cv';
614614
value: number | Cv;
615615
} | null)
616+
| ({
617+
relationTo: 'users';
618+
value: number | User;
619+
} | null)
616620
| ({
617621
relationTo: 'skill';
618622
value: number | Skill;
@@ -644,10 +648,6 @@ export interface PayloadLockedDocument {
644648
| ({
645649
relationTo: 'organisations';
646650
value: number | Organisation;
647-
} | null)
648-
| ({
649-
relationTo: 'users';
650-
value: number | User;
651651
} | null);
652652
globalSlug?: string | null;
653653
user: {
@@ -812,6 +812,35 @@ export interface SocialLinksSelect<T extends boolean = true> {
812812
url?: T;
813813
id?: T;
814814
}
815+
/**
816+
* This interface was referenced by `Config`'s JSON-Schema
817+
* via the `definition` "users_select".
818+
*/
819+
export interface UsersSelect<T extends boolean = true> {
820+
firstName?: T;
821+
lastName?: T;
822+
roles?: T;
823+
organisations?: T | UserOrganisationsSelect<T>;
824+
selectedOrganisation?: T;
825+
updatedAt?: T;
826+
createdAt?: T;
827+
email?: T;
828+
resetPasswordToken?: T;
829+
resetPasswordExpiration?: T;
830+
salt?: T;
831+
hash?: T;
832+
loginAttempts?: T;
833+
lockUntil?: T;
834+
}
835+
/**
836+
* This interface was referenced by `Config`'s JSON-Schema
837+
* via the `definition` "UserOrganisations_select".
838+
*/
839+
export interface UserOrganisationsSelect<T extends boolean = true> {
840+
organisation?: T;
841+
roles?: T;
842+
id?: T;
843+
}
815844
/**
816845
* This interface was referenced by `Config`'s JSON-Schema
817846
* via the `definition` "skill_select".
@@ -898,6 +927,7 @@ export interface MediaSelect<T extends boolean = true> {
898927
organisation?: T;
899928
createdBy?: T;
900929
updatedBy?: T;
930+
prefix?: T;
901931
updatedAt?: T;
902932
createdAt?: T;
903933
url?: T;
@@ -956,36 +986,6 @@ export interface OrganisationsSelect<T extends boolean = true> {
956986
updatedAt?: T;
957987
createdAt?: T;
958988
}
959-
/**
960-
* This interface was referenced by `Config`'s JSON-Schema
961-
* via the `definition` "users_select".
962-
*/
963-
export interface UsersSelect<T extends boolean = true> {
964-
firstName?: T;
965-
lastName?: T;
966-
roles?: T;
967-
organisations?: T | UserOrganisationsSelect<T>;
968-
selectedOrganisation?: T;
969-
sub?: T;
970-
updatedAt?: T;
971-
createdAt?: T;
972-
email?: T;
973-
resetPasswordToken?: T;
974-
resetPasswordExpiration?: T;
975-
salt?: T;
976-
hash?: T;
977-
loginAttempts?: T;
978-
lockUntil?: T;
979-
}
980-
/**
981-
* This interface was referenced by `Config`'s JSON-Schema
982-
* via the `definition` "UserOrganisations_select".
983-
*/
984-
export interface UserOrganisationsSelect<T extends boolean = true> {
985-
organisation?: T;
986-
roles?: T;
987-
id?: T;
988-
}
989989
/**
990990
* This interface was referenced by `Config`'s JSON-Schema
991991
* via the `definition` "payload-locked-documents_select".

0 commit comments

Comments
 (0)