Skip to content

Commit

Permalink
read OAUTH_ENABLED flag server side as client side env vars are resol…
Browse files Browse the repository at this point in the history
…ved at build time only
  • Loading branch information
toggm committed Jan 29, 2025
1 parent 9860629 commit 13ba6ca
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 || '',
Expand Down
6 changes: 3 additions & 3 deletions src/app/(payload)/admin/importMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use client';
export const OAuthLoginButton: React.FC = () => (

type ClientButtonProps = {
oauthEnabled: Boolean;
};

export const OAuthClientLoginButton: React.FC<ClientButtonProps> = ({ oauthEnabled }) => (
<>
{process.env.NEXT_PUBLIC_OAUTH_ENABLE == 'true' && (
{oauthEnabled && (
<div className={'w-full'}>
<button
type={'button'}
Expand Down
9 changes: 9 additions & 0 deletions src/payload/components/oauth-server-login-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { OAuthClientLoginButton } from './oauth-client-login-button';

export const OAuthServerLoginButton: React.FC = () => {
return (
<OAuthClientLoginButton
oauthEnabled={process.env.OAUTH_ENABLED === 'true'}></OAuthClientLoginButton>
);
};
74 changes: 37 additions & 37 deletions src/types/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Config {
};
collections: {
cv: Cv;
users: User;
skill: Skill;
skillGroup: SkillGroup;
langs: Lang;
Expand All @@ -43,14 +44,14 @@ export interface Config {
project: Project;
media: Media;
organisations: Organisation;
users: User;
'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration;
};
collectionsJoins: {};
collectionsSelect: {
cv: CvSelect<false> | CvSelect<true>;
users: UsersSelect<false> | UsersSelect<true>;
skill: SkillSelect<false> | SkillSelect<true>;
skillGroup: SkillGroupSelect<false> | SkillGroupSelect<true>;
langs: LangsSelect<false> | LangsSelect<true>;
Expand All @@ -59,7 +60,6 @@ export interface Config {
project: ProjectSelect<false> | ProjectSelect<true>;
media: MediaSelect<false> | MediaSelect<true>;
organisations: OrganisationsSelect<false> | OrganisationsSelect<true>;
users: UsersSelect<false> | UsersSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
Expand Down Expand Up @@ -399,6 +399,7 @@ export interface Media {
organisation?: (number | null) | Organisation;
createdBy?: (number | null) | User;
updatedBy?: (number | null) | User;
prefix?: string | null;
updatedAt: string;
createdAt: string;
url?: string | null;
Expand Down Expand Up @@ -461,7 +462,6 @@ export interface User {
roles?: ('admin' | 'user')[] | null;
organisations?: UserOrganisations;
selectedOrganisation?: (number | null) | Organisation;
sub?: string | null;
updatedAt: string;
createdAt: string;
email: string;
Expand Down Expand Up @@ -613,6 +613,10 @@ export interface PayloadLockedDocument {
relationTo: 'cv';
value: number | Cv;
} | null)
| ({
relationTo: 'users';
value: number | User;
} | null)
| ({
relationTo: 'skill';
value: number | Skill;
Expand Down Expand Up @@ -644,10 +648,6 @@ export interface PayloadLockedDocument {
| ({
relationTo: 'organisations';
value: number | Organisation;
} | null)
| ({
relationTo: 'users';
value: number | User;
} | null);
globalSlug?: string | null;
user: {
Expand Down Expand Up @@ -812,6 +812,35 @@ export interface SocialLinksSelect<T extends boolean = true> {
url?: T;
id?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
firstName?: T;
lastName?: T;
roles?: T;
organisations?: T | UserOrganisationsSelect<T>;
selectedOrganisation?: T;
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "UserOrganisations_select".
*/
export interface UserOrganisationsSelect<T extends boolean = true> {
organisation?: T;
roles?: T;
id?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "skill_select".
Expand Down Expand Up @@ -898,6 +927,7 @@ export interface MediaSelect<T extends boolean = true> {
organisation?: T;
createdBy?: T;
updatedBy?: T;
prefix?: T;
updatedAt?: T;
createdAt?: T;
url?: T;
Expand Down Expand Up @@ -956,36 +986,6 @@ export interface OrganisationsSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
firstName?: T;
lastName?: T;
roles?: T;
organisations?: T | UserOrganisationsSelect<T>;
selectedOrganisation?: T;
sub?: T;
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "UserOrganisations_select".
*/
export interface UserOrganisationsSelect<T extends boolean = true> {
organisation?: T;
roles?: T;
id?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select".
Expand Down

0 comments on commit 13ba6ca

Please sign in to comment.