-
Notifications
You must be signed in to change notification settings - Fork 140
feat: add expo plugin and trusted origins #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export const envServer = createEnv({ | |
BETTER_AUTH_SECRET: z.string(), | ||
SESSION_EXPIRATION_IN_SECONDS: z.coerce.number().int().default(2592000), // 30 days by default | ||
SESSION_UPDATE_AGE_IN_SECONDS: z.coerce.number().int().default(86400), // 1 day by default | ||
AUTH_TRUSTED_ORIGIN: z.string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainProvide a sane default and reduce friction in local dev. AUTH_TRUSTED_ORIGIN is required with no default, while .env.example suggests "start-ui-native://*". Add a default to keep parity and avoid failures when the env is not set. Apply this diff: - AUTH_TRUSTED_ORIGIN: z.string(),
+ AUTH_TRUSTED_ORIGIN: z.string().default('start-ui-native://*'), Optional (future-proofing): if you decide to support multiple origins via CSV as suggested in .env.example, consider this alternative and adjust downstream code to expect an array: // Optionally add alongside AUTH_TRUSTED_ORIGIN for backwards compatibility:
AUTH_TRUSTED_ORIGINS: z
.string()
.default('start-ui-native://,start-ui-native://*')
.transform((v) =>
v
.split(',')
.map((s) => s.trim())
.filter(Boolean),
), Confirm that app/server/auth.tsx actually consumes envServer.AUTH_TRUSTED_ORIGIN (or the proposed AUTH_TRUSTED_ORIGINS) when building the betterAuth trustedOrigins array, and that you’re not unintentionally hardcoding values: 🏁 Script executed: #!/bin/bash
# Check usage of trustedOrigins and whether the env var is wired through
rg -n -A5 -B5 $'trustedOrigins\\s*:|AUTH_TRUSTED_ORIGIN\\b|AUTH_TRUSTED_ORIGINS\\b' app Length of output: 1339 Provide a sane default for AUTH_TRUSTED_ORIGIN in your env schema To match your • File: - AUTH_TRUSTED_ORIGIN: z.string(),
+ AUTH_TRUSTED_ORIGIN: z.string().default('start-ui-native://*'), Optional future-proofing (support multiple origins via CSV): AUTH_TRUSTED_ORIGINS: z
.string()
.default('start-ui-native://,start-ui-native://*')
.transform(v =>
v
.split(',')
.map(s => s.trim())
.filter(Boolean),
) Note: 🤖 Prompt for AI Agents
|
||
|
||
GITHUB_CLIENT_ID: zOptionalWithReplaceMe(), | ||
GITHUB_CLIENT_SECRET: zOptionalWithReplaceMe(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { expo } from '@better-auth/expo'; | ||
import { betterAuth } from 'better-auth'; | ||
import { prismaAdapter } from 'better-auth/adapters/prisma'; | ||
import { admin, emailOTP, openAPI } from 'better-auth/plugins'; | ||
|
@@ -24,6 +25,7 @@ export const auth = betterAuth({ | |
expiresIn: envServer.SESSION_EXPIRATION_IN_SECONDS, | ||
updateAge: envServer.SESSION_UPDATE_AGE_IN_SECONDS, | ||
}, | ||
trustedOrigins: [envServer.AUTH_TRUSTED_ORIGIN], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment to explain the purpose of this line would be great so people not using Start UI [native] will know that they can remove it. |
||
database: prismaAdapter(db, { | ||
provider: 'postgresql', | ||
}), | ||
|
@@ -46,7 +48,9 @@ export const auth = betterAuth({ | |
disableImplicitSignUp: !AUTH_SIGNUP_ENABLED, | ||
}, | ||
}, | ||
|
||
plugins: [ | ||
expo(), | ||
openAPI({ | ||
disableDefaultReference: true, // Use custom exposition in /routes/api/openapi folder | ||
}), | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Align env var with array semantics and allow multiple trusted origins (CSV).
better-auth expects an array for trustedOrigins. A single AUTH_TRUSTED_ORIGIN is limiting and semantically singular. Consider switching to a plural, comma-separated env to support multiple entries out of the box.
Apply this diff to the example:
Follow-up:
Run to locate all usages and assess impact (rename vs. dual support):
Additionally, verify whether better-auth accepts the wildcard form for custom schemes or if plain "scheme://" is sufficient:
🏁 Script executed:
Length of output: 756
🌐 Web query:
💡 Result:
Better Auth accepts the following formats for the
trustedOrigins
option:start-ui-native://
for deep links and mobile authentication flows[1][3][4].Custom URL Schemes Support:
start-ui-native://
to enable deep linking for mobile or desktop apps[3][4]."start-ui-native://"
)."start-ui-native://*"
)[3].Illustrative Example:
Key Details:
start-ui-native
) must match exactly—wildcarding does not change the protocol/scheme matching logic[4]."https://*.example.com"
,"*.example.com"
), with HTTPS preferred for security[4][1].References:
In summary:
Better Auth’s
trustedOrigins
can accept static URLs, dynamic lists, wildcard patterns, and custom URL schemes (including wildcards such asstart-ui-native://*
). Custom URL schemes are a first-class feature for deep linking in mobile and desktop apps and should be explicitly listed in your configuration for safe origin handling[3][4].Citations:
Align AUTH_TRUSTED_ORIGINS for multiple origins
To support an array of trusted origins while preserving backward-compatibility:
• .env.example
• app/env/server.ts
– Replace
AUTH_TRUSTED_ORIGIN: z.string()
– Add
AUTH_TRUSTED_ORIGINS: z.string().default('').transform(s => s.split(',').filter(Boolean))
– In your server config, coalesce:
• app/server/auth.tsx
– Change
to
Ensure you read the new
AUTH_TRUSTED_ORIGINS
CSV first and fall back to the legacyAUTH_TRUSTED_ORIGIN
for a smooth migration.🤖 Prompt for AI Agents