Firebase "auth/unauthorized-domain": the fix for Google sign-in that works on localhost but not in production
Google sign-in works on localhost, then you deploy and get:
FirebaseError: Firebase: Error (auth/unauthorized-domain). The popup closes or the redirect fails, and only on your live domain. This one is quick to fix. The safe way matters, because the wrong shortcut opens the door to other sites.
What it means
Firebase Auth only allows OAuth sign-in (Google, GitHub, and so on) from domains you have approved. Your deployed domain is not on that list, so Firebase refuses the request. localhost is approved by default, which is why it worked there.
The usual causes
- New hosting domain. Vercel, Netlify, Replit, Lovable and Bolt each give you a new URL for production or for every preview deploy.
- A custom domain added after launch. The new domain was never added.
-
wwwvs non-www.example.comandwww.example.comare separate entries. - Preview URLs. Each branch deploy has its own hostname.
- Wrong Firebase project. The deployed build uses the config of a different project than the one you edited.
The fix, in order
- Open the Firebase console, go to Authentication, Settings, Authorized domains.
- Add the exact domain shown in the browser address bar of the failing page, with no
https://and no path. - Add both
wwwand non-wwwif you serve both. - Confirm the
authDomainandprojectIdin your deployed config match this project. - Retry in a private window.
Fixes to avoid
- Do not add wildcard-like shortcuts or domains you do not control to make the error disappear. Every authorized domain can start a sign-in flow for your project.
- Do not leave old preview domains forever. Remove ones you no longer use.
- Do not confuse this with security rules. Authorized domains control sign-in only. Your Firestore and Storage rules still decide who can read data.
Check your rules while you are there
A working login says nothing about whether your data is protected. If your rules still say allow read, write: if true, anyone can read and write. The free read-only check at https://proofforge.live looks at a deployed site for open Firebase data, leaked keys and exposed files, and lists what it could not test. For checking that one user cannot read another's data, there is the free two-account test: https://proofforge.live/two-account-test
Paid one-time fix reports are $9, $29 and $79, and the free scan does not require them.