fix: proxy Firebase auth handler so Safari mobile redirect login completes (#4067)#4071
Conversation
signInWithRedirect returned no user on iOS Safari because authDomain (bypass-links.firebaseapp.com) is a different origin than the app; Safari's ITP blocks the cross-origin auth-handler storage. Serve /__/auth and /__/firebase from our own domain via next.config rewrites and point the prod authDomain at bypass-links.vercel.app so the whole flow is same-origin. https://firebase.google.com/docs/auth/web/redirect-best-practices Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
authHelperdomain innext.config.tsis hard-coded; consider reading this from environment or a shared config so staging/preview deployments and future domain changes don’t require code edits. - Since
rewrites()applies in all environments, double-check whether you want the Firebase proxy behavior in local/dev as well; if not, gate the rewrites onprocess.env.NODE_ENVor a dedicated flag.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `authHelper` domain in `next.config.ts` is hard-coded; consider reading this from environment or a shared config so staging/preview deployments and future domain changes don’t require code edits.
- Since `rewrites()` applies in all environments, double-check whether you want the Firebase proxy behavior in local/dev as well; if not, gate the rewrites on `process.env.NODE_ENV` or a dedicated flag.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
📝 WalkthroughWalkthroughProduction Firebase configuration now sets 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review by Qodo
1. Auth domain host mismatch
|
Add a `dev:https` script and, when dev runs over https, set authDomain to the current origin so signInWithRedirect stays same-origin via the /__/auth proxy (Firebase forces https://<authDomain>/__/auth/handler). Make the proxy target env-aware so dev proxies to the dev Firebase project. Default http `pnpm dev` and e2e are unaffected. Requires https://localhost:3000/__/auth/handler on the dev OAuth client. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The same-origin redirect fix is prod-only; supporting local dev would need https dev + a separate OAuth redirect URI. Document why dev is left as-is. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Context
Follow-up to #4070. That change made mobile use
signInWithRedirect, but on iOS Safari the redirect returned no user —getRedirectResult()resolvednulland the button stayed on "Login".Root cause:
authDomain(bypass-links.firebaseapp.com) is a different origin than the app (bypass-links.vercel.app). Firebase completes the redirect by reading state from a cross-origin iframe onfirebaseapp.com, which Safari's ITP blocks. (The/__/firebase/init.json404 in the Network tab was a symptom.)Fix
Make the auth handler same-origin with the app, per Firebase's redirect best practices:
apps/web/next.config.ts—rewrites()transparently proxy/__/auth/*and/__/firebase/*tobypass-links.firebaseapp.com.packages/configs/firebase.config.ts— prodauthDomain→bypass-links.vercel.app(dev unchanged).Prerequisite (done):
https://bypass-links.vercel.app/__/auth/handleradded as an Authorized redirect URI on the web OAuth client.Rollback: revert the one
authDomainline + redeploy; the oldfirebaseapp.comredirect URI is still registered.Check if the Pull Request fulfils these requirements
🤖 Generated with Claude Code
Greptile Summary
This PR fixes Safari ITP blocking
signInWithRedirecton iOS by making the Firebase auth handler same-origin with the app. The approach follows Firebase's official redirect best-practices guide.next.config.tsadds transparent Next.js rewrites that proxy/__/auth/*and/__/firebase/*tobypass-links.firebaseapp.com, making the auth handler reachable on the app's own domain.firebase.config.tschanges the prodauthDomainfrombypass-links.firebaseapp.comtobypass-links.vercel.appso Firebase SDK directs redirect traffic through the same-origin proxy.Confidence Score: 5/5
Safe to merge for production; the fix is the standard Firebase-recommended approach and scoped correctly to prod config.
The change is a well-understood pattern (same-origin proxy for Firebase auth) with no functional issues on the production deployment. The one concern worth watching is that Vercel preview deployments inherit NODE_ENV=production, so auth redirects on preview URLs will land on the production domain — a workflow inconvenience rather than a production regression.
The authDomain / NODE_ENV coupling in packages/configs/firebase.config.ts and apps/web/src/app/helpers/firebase/index.ts is worth revisiting if preview deployments need to exercise the auth flow.
Reviews (4): Last reviewed commit: "revert: drop dev-mode redirect handling" | Re-trigger Greptile