OAuth Proxy State Mismatch Issue with Localhost → Production Flow
@Better Auth
We're using
Steps 1-4 work correctly, but at step 5:
We're using
better-auth with the oAuthProxy plugin to enable OAuth login from localhost through our production deployment, since our OAuth provider (AWS Cognito) only has the production URL whitelisted.Expected Flow
- User clicks sign-in on
localhost:3000 - OAuth state is created and stored (cookie/database)
- User redirected to OAuth provider with
redirect_uri=https://production.example.com/api/auth/callback/cognito&state=xyz - OAuth provider redirects back to
https://production.example.com/api/auth/callback/cognito?code=...&state=xyz - Production should skip state cookie check (since it was initiated from localhost)
- Production validates the code and proxies back to localhost with encrypted cookies
Steps 1-4 work correctly, but at step 5:
- Production receives the callback with
state=<state-value> - Production tries to verify the state cookie, but the cookie is on localhost, not production
- Production returns
state_mismatcherror