Skip to content

Commit 04dc4a5

Browse files
committed
fix: AUTH_TRUSTED_ORIGINS and allows vercel urls
1 parent 3f58dad commit 04dc4a5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DATABASE_URL="postgres://${DOCKER_DATABASE_USERNAME}:${DOCKER_DATABASE_PASSWORD}
2323
BETTER_AUTH_SECRET="REPLACE ME" # You can use `npx @better-auth/cli@latest secret` to a generated secret
2424
SESSION_EXPIRATION_IN_SECONDS=2592000 # 30 days
2525
SESSION_UPDATE_AGE_IN_SECONDS=86400 # 1 day (every 1 day the session expiration is updated)
26-
AUTH_TRUSTED_ORIGIN="start-ui-native://,start-ui-native://*" # Mobile app scheme for trustedOrigins config
26+
AUTH_TRUSTED_ORIGINS="start-ui-native://,start-ui-native://*" # Mobile app scheme for trustedOrigins config
2727

2828
# GITHUB
2929
GITHUB_CLIENT_ID="REPLACE ME"

src/env/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const envServer = createEnv({
1212
BETTER_AUTH_SECRET: z.string(),
1313
SESSION_EXPIRATION_IN_SECONDS: z.coerce.number().int().prefault(2592000), // 30 days by default
1414
SESSION_UPDATE_AGE_IN_SECONDS: z.coerce.number().int().prefault(86400), // 1 day by default
15-
AUTH_TRUSTED_ORIGIN: z.string().optional(),
15+
AUTH_TRUSTED_ORIGINS: z.string().optional(), // Trusted origins, useful for React Native
1616

1717
GITHUB_CLIENT_ID: zOptionalWithReplaceMe(),
1818
GITHUB_CLIENT_SECRET: zOptionalWithReplaceMe(),

src/server/auth.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ export const auth = betterAuth({
2525
expiresIn: envServer.SESSION_EXPIRATION_IN_SECONDS,
2626
updateAge: envServer.SESSION_UPDATE_AGE_IN_SECONDS,
2727
},
28-
// Allows an Expo native app to use social auth, can be delete if no needed
29-
trustedOrigins: envServer.AUTH_TRUSTED_ORIGIN
30-
? envServer.AUTH_TRUSTED_ORIGIN.split(',')
31-
: undefined,
28+
trustedOrigins: [
29+
// Setup custom trusted origins, useful for React Native
30+
...(envServer.AUTH_TRUSTED_ORIGINS
31+
? envServer.AUTH_TRUSTED_ORIGINS.split(',')
32+
: []),
33+
34+
// Setup vercel urls as trusted origins
35+
// eslint-disable-next-line no-process-env
36+
...(process.env.VERCEL_URL ? [process.env.VERCEL_URL] : []),
37+
// eslint-disable-next-line no-process-env
38+
...(process.env.VERCEL_BRANCH_URL ? [process.env.VERCEL_BRANCH_URL] : []),
39+
],
3240
database: prismaAdapter(db, {
3341
provider: 'postgresql',
3442
}),

0 commit comments

Comments
 (0)