Skip to content

feat(auth): trust dev frontend origins (Expo web :8081) for CORS + Better-Auth#160

Merged
pascal-klesse merged 1 commit into
mainfrom
feat/trust-dev-frontend-origins
May 21, 2026
Merged

feat(auth): trust dev frontend origins (Expo web :8081) for CORS + Better-Auth#160
pascal-klesse merged 1 commit into
mainfrom
feat/trust-dev-frontend-origins

Conversation

@pascal-klesse
Copy link
Copy Markdown
Member

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:

  1. The dev CORS allowlist (corsDefaults("development")) only had :3000, :3001, :5173, app.nst.localhost → preflight blocked.
  2. Even past CORS, Better-Auth's own origin guard (trustedOrigins, separate from CORS) rejected the request with "Invalid origin".

Fix

  • corsDefaults("development"): add http://localhost:8081 + http://localhost:19006 (Expo web / Metro dev ports).
  • buildBetterAuth: new optional trustedOrigins; BetterAuthModule feeds it corsDefaults(env).allowedOrigins, so CORS and Better-Auth's trusted-origin set share one source of truth. The baseURL stays implicitly trusted.

Verification

POST /api/auth/sign-up/email with Origin: http://localhost:8081 now returns 200 (previously "Invalid origin"). Extends tests/cookies-cors-config.spec.ts with a :8081 assertion. Local gates green: lint (0 errors), cors spec (12/12), test:types.

…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").
@pascal-klesse pascal-klesse merged commit 4c630db into main May 21, 2026
13 checks passed
@pascal-klesse pascal-klesse deleted the feat/trust-dev-frontend-origins branch May 21, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant