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…
Firebase sign-in errors persist from local testing to live production. The error message "Firebase: Error (auth/unauthorized-domain)" appears when clicking on the website, closing the popup or failing redirects. This issue affects only the live domain, not the localhost environment.
Firebase Auth only permits OAuth sign-in from approved domains. The deployed domain is not on the approved list, causing Firebase to reject the request. New hosting domains, custom domains, www vs non-www entries, preview URLs, and wrong Firebase projects can all contribute to the problem.
To resolve this error, log in to the Firebase console, go to Authentication settings, and add the exact domain displayed in the failing page's browser address bar. Include both www and non-www variants if applicable. Ensure the authDomain and projectId in the deployed config match the corresponding project. Retry accessing the site in a private window.
Avoid adding wildcard-like shortcuts or domains not under control, as this can create security vulnerabilities. Remove old preview domains no longer in use. Authorized domains control sign-in, but security rules determine data access. Check both to ensure proper protection. If rules still say "allow read, write: if true, anyone can read and write."
Free tools like proofforge.live can scan for open data, leaked keys, and exposed files. For checking specific user data access issues, a two-account test is available on the same website. Paid one-time fix reports start at $9.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to