feat(auth): trust dev frontend origins (Expo web :8081) for CORS + Better-Auth#160
Merged
Merged
Conversation
…tter-Auth
A frontend dev server on a port outside the dev CORS allowlist could not
sign up / sign in cross-origin: CORS preflight blocked it, and even past
CORS, Better-Auth's own origin guard (trustedOrigins — separate from CORS)
rejected it with "Invalid origin".
- corsDefaults("development"): add http://localhost:8081 + :19006 (the
Expo web / Metro dev server ports) alongside the existing Nuxt/Vite ones.
- buildBetterAuth: new optional `trustedOrigins`; BetterAuthModule feeds it
corsDefaults(env).allowedOrigins so CORS and Better-Auth's trusted-origin
set share a single source of truth. baseURL stays implicitly trusted.
Verified: POST /api/auth/sign-up/email with Origin http://localhost:8081
returns 200 (previously "Invalid origin").
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A frontend dev server running on a port outside the dev CORS allowlist (e.g. Expo Web / Metro on
:8081) cannot sign up or sign in cross-origin against the dev API. It fails twice over:corsDefaults("development")) only had:3000,:3001,:5173,app.nst.localhost→ preflight blocked.trustedOrigins, separate from CORS) rejected the request with"Invalid origin".Fix
corsDefaults("development"): addhttp://localhost:8081+http://localhost:19006(Expo web / Metro dev ports).buildBetterAuth: new optionaltrustedOrigins;BetterAuthModulefeeds itcorsDefaults(env).allowedOrigins, so CORS and Better-Auth's trusted-origin set share one source of truth. ThebaseURLstays implicitly trusted.Verification
POST /api/auth/sign-up/emailwithOrigin: http://localhost:8081now returns200(previously"Invalid origin"). Extendstests/cookies-cors-config.spec.tswith a:8081assertion. Local gates green: lint (0 errors), cors spec (12/12), test:types.