Firebase "auth/unauthorized-domain": Why Sign-In Fails and How to Fix It
Firebase auth/unauthorized-domain means your site's domain isn't in the project's Authorized domains list. Add the exact hostname in the Firebase console.
"Firebase: Error (auth/unauthorized-domain)" means the page you're signing in from is on a domain that isn't in your Firebase project's list of authorized domains, so Firebase refuses to start a popup or redirect sign-in (Google, GitHub, Apple and other OAuth providers). Fix it in the Firebase console: open Authentication, go to the Settings tab, find Authorized domains and click Add domain, then enter the exact hostname you see in the address bar, without https://, a port or a path. It usually appears right after you deploy to a new domain or open a preview URL, and on localhost in projects created after 28 April 2025, which no longer include localhost by default.
Checked against Firebase's docs (Authentication FAQ and troubleshooting, signInWithRedirect best practices and Google sign-in for web) and the source of the Firebase JS SDK (firebase 13.4.0, which ships @firebase/auth 1.13.11 and @firebase/util 1.15.3) in November 2026.
In the browser console it looks like this:
FirebaseError: Firebase: Error (auth/unauthorized-domain).
With a popup, the window opens and then closes again. With a redirect, nothing happens: the SDK checks the domain before it leaves the page, so you never reach Google's sign-in screen.
Why the message just says "Error"
The SDK has a full explanation for this code, but getAuth() loads a minimal error map to keep bundles small, so you only get the code. The full text, from the SDK source, is:
This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.
To see full messages while developing, initialize Auth with the debug error map instead of calling getAuth():
import {
initializeAuth, debugErrorMap,
browserLocalPersistence, browserPopupRedirectResolver,
} from "firebase/auth";
const auth = initializeAuth(app, {
persistence: browserLocalPersistence,
popupRedirectResolver: browserPopupRedirectResolver,
errorMap: debugErrorMap,
});
When Firebase checks the domain
Only for sign-ins that go through a popup or a redirect: signInWithPopup, signInWithRedirect, and the matching link and reauthenticate functions. Email and password sign-in doesn't hit this check. When you're connected to the Auth emulator the check is skipped, which is why sign-in can work against the emulator and fail against the real project.
The SDK fetches the authorized domains list for your project and compares it with the current page's hostname. From the source, a few details are worth knowing:
- The port doesn't matter.
localhostcoverslocalhost:5173andlocalhost:3000. localhostand127.0.0.1are different. IP addresses must match exactly, so if you open your dev server athttp://127.0.0.1:5173, add127.0.0.1too, or uselocalhost.- An entry also covers its subdomains in the SDK's check:
example.commatcheswww.example.com.www.example.comdoesn't matchexample.com. - Only
httpandhttpspages pass, apart from Chrome extensions, which have their own rule.
Step 1: find the exact hostname
Open the page where sign-in fails and run this in the browser console:
location.hostname
That's what goes in the list. Common surprises: www. versus the bare domain, a platform hostname like my-app.vercel.app instead of your custom domain, or 127.0.0.1 instead of localhost.
Step 2: add it to Authorized domains
- Open the Firebase console and select the right project.
- Go to Authentication, then the Settings tab.
- Under Authorized domains, click Add domain.
- Enter the hostname only, such as
app.example.com.
Then reload the page and try again.
Check it's the right project. If you have separate development and production projects, the domain has to be added to the project your deployed firebaseConfig points at. Compare projectId in the config your app actually loads (environment variables on the host included) with the project open in the console.
The usual reasons a domain is missing
Localhost in a newer project. Firebase's FAQ says that "In projects created after April 28, 2025, Firebase Authentication no longer includes localhost as an authorized domain by default." Older projects still have it. Google also "strongly discourages the use of localhost in production projects," because anyone can run code on their own localhost against your project. The clean setup is a separate Firebase project for development with localhost authorized, and a production project without it. If you add it to production anyway, remove it later.
You deployed somewhere new. Moving from Firebase Hosting to Vercel, Netlify or your own server, or attaching a custom domain, means a hostname the project has never seen. Add each one users sign in from. Your Firebase Hosting domains (PROJECT_ID.web.app and PROJECT_ID.firebaseapp.com) are normally already listed, but check rather than assume.
Preview URLs. Preview deployments usually get a new hostname per branch or per deploy, so each one fails until it's added. Add the few you actually test sign-in on, or give previews a stable hostname under your own domain. Don't add a hosting platform's shared domain (such as vercel.app) to make every preview work: because entries cover subdomains, that would authorize every other app on that platform too. Preview Environments for Every Branch covers previews in general.
AI app builder previews. Apps built in Lovable, Bolt, Replit or similar run their previews on the builder's hostname, which needs adding like any other. When you move the app to its real home (deploying a Lovable app), add the new domain too.
A related error: "This domain ... is not authorized to run this operation"
If the error page appears on your authDomain (by default PROJECT_ID.firebaseapp.com) during a redirect, with the message This domain YOUR_REDIRECT_DOMAIN is not authorized to run this operation., Firebase's FAQ gives two causes: the domain you're redirecting back to isn't an authorized domain, or the API key in your config is invalid. Add the domain, then check that apiKey and projectId in firebaseConfig belong to the same project.
authDomain and signInWithRedirect
This is a separate problem, but it often turns up while you're fixing the one above. Chrome 115+, Firefox 109+ and Safari 16.1+ block the third-party storage that signInWithRedirect relied on when your app and your authDomain are on different domains. Apps served from PROJECT_ID.firebaseapp.com aren't affected. Everyone else should pick one of the options in Firebase's best-practices guide:
| Option | What you do | Notes |
|---|---|---|
Use signInWithPopup |
Swap the redirect call for a popup | Simplest; popups can be blocked, and are less smooth on mobile |
Your domain as authDomain |
Set authDomain to your custom domain or web.app domain on Firebase Hosting |
Add https://<your-domain>/__/auth/handler to the OAuth provider's redirect URIs |
Proxy /__/auth |
On other hosts, reverse-proxy /__/auth to PROJECT_ID.firebaseapp.com and set authDomain to your domain |
Must be a real proxy; the docs say "this cannot be done via a 302 Redirect" |
The guide's Nginx example for the proxy option:
location /__/auth {
proxy_pass https://<project>.firebaseapp.com;
}
Whatever you set authDomain to, the domain your users load the app from still has to be in Authorized domains. The guide also lists self-hosting the helper files and handling provider sign-in yourself; both take more maintenance.
Quick checklist
- Run
location.hostnameon the failing page. - Firebase console > Authentication > Settings > Authorized domains > Add domain, hostname only.
- Confirm the console project matches
projectIdin the config your app loads. - Using
127.0.0.1? Add it too, or switch tolocalhost. - New project (after 28 April 2025)? Add
localhostin a development project, not production. - Using
signInWithRedirectoff Firebase Hosting? Switch to a popup, or setauthDomainto your domain and proxy/__/auth.
EasySpawn doesn't manage your Firebase project, so adding a domain to Authorized domains is still a console step for you. It does affect which domains you need: every branch on EasySpawn gets its own live URL, and each is a new hostname as far as Firebase is concerned, so add the ones you test sign-in on, or point your own domain at the app. Claude Code on the server can read the config your app actually loads and tell you which hostname and project to check. See how it works or join the waitlist.
Related: What Is Firebase? Google's App Backend Explained for Beginners · How to Connect a Custom Domain to Your App: DNS Without the Jargon · Supabase vs Firebase: Which Backend for Your First App?
Keep reading
ERR_SSL_PROTOCOL_ERROR: What It Means and How to Fix It
ERR_SSL_PROTOCOL_ERROR means the browser couldn't complete a secure HTTPS connection because the server's response wasn't valid TLS. The usual causes — HTTPS pointed at a port speaking plain HTTP, a missing certificate, localhost over https, Cloudflare SSL modes — and how to fix each.
I Leaked an API Key. What Now? A Step-by-Step Response
You pushed a .env file to GitHub, pasted a key in a screenshot, or found your secret key in your app's frontend code. What to do in the next ten minutes, the next hour, and the next day — revoke, rotate, check for abuse, clean up — and how to stop it happening again.