Skip to content

Commit c89a95d

Browse files
authored
feat(auth): add DISABLE_GOOGLE_AUTH and DISABLE_GITHUB_AUTH env vars (#4019)
* feat(auth): add DISABLE_GOOGLE_AUTH and DISABLE_GITHUB_AUTH env vars * fix(auth): also disable server-side OAuth provider registration when flags are set * lint
1 parent 8372332 commit c89a95d

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { env } from '@/lib/core/config/env'
2-
import { isProd } from '@/lib/core/config/feature-flags'
2+
import { isGithubAuthDisabled, isGoogleAuthDisabled, isProd } from '@/lib/core/config/feature-flags'
33

44
export async function getOAuthProviderStatus() {
5-
const githubAvailable = !!(env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET)
5+
const githubAvailable =
6+
!!(env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET) && !isGithubAuthDisabled
67

7-
const googleAvailable = !!(env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET)
8+
const googleAvailable =
9+
!!(env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET) && !isGoogleAuthDisabled
810

911
return { githubAvailable, googleAvailable, isProduction: isProd }
1012
}

apps/sim/lib/auth/auth.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import {
6565
isBillingEnabled,
6666
isEmailPasswordEnabled,
6767
isEmailVerificationEnabled,
68+
isGithubAuthDisabled,
69+
isGoogleAuthDisabled,
6870
isHosted,
6971
isOrganizationsEnabled,
7072
isRegistrationDisabled,
@@ -607,19 +609,23 @@ export const auth = betterAuth({
607609
},
608610
},
609611
socialProviders: {
610-
github: {
611-
clientId: env.GITHUB_CLIENT_ID as string,
612-
clientSecret: env.GITHUB_CLIENT_SECRET as string,
613-
scope: ['user:email', 'repo'],
614-
},
615-
google: {
616-
clientId: env.GOOGLE_CLIENT_ID as string,
617-
clientSecret: env.GOOGLE_CLIENT_SECRET as string,
618-
scope: [
619-
'https://www.googleapis.com/auth/userinfo.email',
620-
'https://www.googleapis.com/auth/userinfo.profile',
621-
],
622-
},
612+
...(!isGithubAuthDisabled && {
613+
github: {
614+
clientId: env.GITHUB_CLIENT_ID as string,
615+
clientSecret: env.GITHUB_CLIENT_SECRET as string,
616+
scope: ['user:email', 'repo'],
617+
},
618+
}),
619+
...(!isGoogleAuthDisabled && {
620+
google: {
621+
clientId: env.GOOGLE_CLIENT_ID as string,
622+
clientSecret: env.GOOGLE_CLIENT_SECRET as string,
623+
scope: [
624+
'https://www.googleapis.com/auth/userinfo.email',
625+
'https://www.googleapis.com/auth/userinfo.profile',
626+
],
627+
},
628+
}),
623629
},
624630
emailVerification: {
625631
autoSignInAfterVerification: true,

apps/sim/lib/core/config/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ export const env = createEnv({
260260
GOOGLE_CLIENT_SECRET: z.string().optional(), // Google OAuth client secret
261261
GITHUB_CLIENT_ID: z.string().optional(), // GitHub OAuth client ID for GitHub integration
262262
GITHUB_CLIENT_SECRET: z.string().optional(), // GitHub OAuth client secret
263+
DISABLE_GOOGLE_AUTH: z.boolean().optional(), // Disable Google OAuth login even when credentials are configured
264+
DISABLE_GITHUB_AUTH: z.boolean().optional(), // Disable GitHub OAuth login even when credentials are configured
263265

264266
X_CLIENT_ID: z.string().optional(), // X (Twitter) OAuth client ID
265267
X_CLIENT_SECRET: z.string().optional(), // X (Twitter) OAuth client secret

apps/sim/lib/core/config/feature-flags.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ export const isInvitationsDisabled = isTruthy(env.DISABLE_INVITATIONS)
150150
*/
151151
export const isPublicApiDisabled = isTruthy(env.DISABLE_PUBLIC_API)
152152

153+
/**
154+
* Is Google OAuth login disabled
155+
* When true, the Google OAuth login button is hidden even when credentials are configured
156+
*/
157+
export const isGoogleAuthDisabled = isTruthy(env.DISABLE_GOOGLE_AUTH)
158+
159+
/**
160+
* Is GitHub OAuth login disabled
161+
* When true, the GitHub OAuth login button is hidden even when credentials are configured
162+
*/
163+
export const isGithubAuthDisabled = isTruthy(env.DISABLE_GITHUB_AUTH)
164+
153165
/**
154166
* Is React Grab enabled for UI element debugging
155167
* When true and in development mode, enables React Grab for copying UI element context to clipboard

helm/sim/examples/values-production.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ app:
4545
RESEND_API_KEY: "your-resend-api-key"
4646
GOOGLE_CLIENT_ID: "your-google-client-id"
4747
GOOGLE_CLIENT_SECRET: "your-google-client-secret"
48+
# DISABLE_GOOGLE_AUTH: "true" # Uncomment to hide Google OAuth login
49+
# DISABLE_GITHUB_AUTH: "true" # Uncomment to hide GitHub OAuth login
4850

4951
# Realtime service
5052
realtime:

helm/sim/values.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@
184184
"type": "string",
185185
"description": "GitHub OAuth client secret"
186186
},
187+
"DISABLE_GOOGLE_AUTH": {
188+
"type": "string",
189+
"description": "Set to 'true' to hide Google OAuth login even when credentials are configured"
190+
},
191+
"DISABLE_GITHUB_AUTH": {
192+
"type": "string",
193+
"description": "Set to 'true' to hide GitHub OAuth login even when credentials are configured"
194+
},
187195
"OPENAI_API_KEY": {
188196
"type": "string",
189197
"description": "Primary OpenAI API key"

helm/sim/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ app:
109109
GOOGLE_CLIENT_SECRET: "" # Google OAuth client secret
110110
GITHUB_CLIENT_ID: "" # GitHub OAuth client ID
111111
GITHUB_CLIENT_SECRET: "" # GitHub OAuth client secret
112+
DISABLE_GOOGLE_AUTH: "" # Set to "true" to hide Google OAuth login
113+
DISABLE_GITHUB_AUTH: "" # Set to "true" to hide GitHub OAuth login
112114

113115
# Google Vertex AI Configuration
114116
VERTEX_PROJECT: "" # Google Cloud project ID for Vertex AI

0 commit comments

Comments
 (0)