Firebase: Error (auth/unauthorized-domain)

Filed under APIs, auth & CORS

Most likely causeAbout 10 min · 6 steps

Your app is running on a domain that is not in your Firebase project's authorized domains list, so Firebase refuses to start the sign-in flow.

Copy the exact domain from the address bar
Add it under Authorized domains
Check the Google Cloud origins too

Fastest route

Give your AI this prompt

Copy it, replace the bracketed part with your error, and send it.

Preview the prompt
My app uses Firebase Authentication and sign-in fails with: Firebase: Error (auth/unauthorized-domain).

The address in my browser when it fails is: [paste the exact URL, including www or any subdomain].
My Firebase project is: [project name], and my app is hosted on: [Vercel / Netlify / Firebase Hosting / other].

Please: 1) tell me exactly what to add in Firebase Console under Authentication > Settings > Authorized domains for my address — spelling out whether www and non-www both need entries, 2) if I use Google sign-in, tell me what to check in Google Cloud Console under APIs & Services > Credentials for the OAuth Web client (Authorized JavaScript origins and Authorized redirect URIs, including the /__/auth/handler URI), 3) explain how preview deployment URLs interact with this restriction and what my options are, 4) give me a short checklist to verify the fix in a clean browser window.

Constraints: do not suggest switching auth providers, do not suggest removing domains from the authorized list other than ones I identify as wrong, and flag any step that involves waiting for a change to propagate.

Fix it yourself

Follow the repair

  1. Note the exact domain in your browser's address bar. Not the domain you meant to use — the one actually shown when the error fires. Copy it exactly, including whether it starts with www. Most failed fixes are the right idea applied to a slightly different address than the one the app really runs on.
  2. Add that domain to Firebase's authorized list. In the Firebase Console for your project: Authentication > Settings (the gear or tab at the top of the Authentication section) > Authorized domains > Add domain. Type the domain by itself — example.com or app.example.com — with no https:// and no path after it:
    Authorized domains
      localhost                       (built in)
      your-project.firebaseapp.com    (built in)
      your-project.web.app            (built in)
      example.com                     <- add this
      www.example.com                 <- and this, if you use it
    If both the www and bare versions of your domain can serve the app, add both. Add does not support wildcards, so *.example.com is not an option — every subdomain gets its own line.
  3. Retry in a fresh tab, and give it a few minutes. Close the tab with the error, wait a couple of minutes for the change to propagate, and open the app again (an incognito window is a clean test, since nothing is cached). If the sign-in popup now opens and completes, you are done. If it fails differently, note the new error — it usually means you have moved on to step 4's problem, which is progress, not a new failure.
  4. If you use Google sign-in, check the Google Cloud side too. Firebase's list is only half the story for OAuth providers. In Google Cloud Console, open the same project, go to APIs & Services > Credentials, and open the Web OAuth client. Under Authorized JavaScript origins, add your app's full origin — this time with the scheme: https://example.com. Under Authorized redirect URIs, make sure https://example.com/__/auth/handler is present (use your real domain; your Firebase authDomain uses the same handler pattern). A domain fixed in Firebase but missing here produces a redirect_uri or origin error right after the popup — the tell-tale sign of this second list.
  5. Handle preview deployments deliberately. If your host generates a unique URL per deployment, you cannot authorize them all — there is a new one every push, and wildcards are not supported. Instead: test sign-in on your stable domains (production, or a fixed staging domain your host lets you keep), and treat social sign-in on throwaway preview URLs as expected-to-fail. If your team truly needs working auth on previews, give previews one permanent staging address and authorize that.
  6. If it worked yesterday and broke today, ask what address changed. This error returning uninvited almost always means the app is being reached at a new address: a domain settings change, a www redirect that stopped working, a marketing page embedding the app from a new host, or a user opening the raw hosting URL from an old bookmark. Re-check step 1's address bar against the authorized list — the difference, once spotted, is usually one subdomain wide.
Why this happensOptional explanation

Firebase Authentication will only start a sign-in flow from a domain you have told it to trust. That is a security feature — it stops someone from copying your public Firebase config (which is visible in your site's code by design) onto their own scam site and running sign-ins as your app. The cost is friction every time your app gains a new address: the day you connect a custom domain, share a preview link, or open the deployed site instead of localhost, this error appears — usually the moment the first real user clicks "Sign in with Google."

It ambushes people at predictable moments. Everything worked on localhost, because localhost is pre-authorized. Everything worked on the firebaseapp.com address Firebase gave you, because that is pre-authorized too. Then the app moves to its real home — a Vercel domain, a custom domain, a Netlify subdomain — and that address is a stranger to Firebase until you introduce it. Preview deployments are the sneaky version: hosts like Vercel mint a brand-new URL for every deployment, so the preview you shared today has a different domain from the preview you tested yesterday.

  • Custom domain connected: your app now lives at your own domain, which Firebase has never been told about.
  • Preview or staging URL: a per-deployment address that differs from the production one you authorized.
  • www vs no www: you authorized example.com but the app is being visited at www.example.com, or the reverse — Firebase treats them as different domains.
  • Opened the wrong address: the same app reached through its raw hosting URL instead of the domain you set up.

Quick answers

Why does sign-in work on localhost but fail on my real domain?

Because localhost is on the built-in authorized list, alongside your project's firebaseapp.com and web.app addresses. Your deployed domain is a new address Firebase has never been told to trust, so the first sign-in attempt there is refused. Add the exact domain and the same code works.

Can I add a wildcard like *.example.com to cover everything?

No. Firebase does not support wildcard entries in authorized domains — every distinct domain and subdomain needs its own line. That is also why per-deployment preview URLs, which change every push, cannot be covered this way; test auth on a stable staging or production domain instead.

I added the domain but Google sign-in now fails with a different error. What gives?

Fix the Google Cloud side too. In Google Cloud Console, under APIs and Services, Credentials, open the OAuth Web client and add your origin (https://your-domain) to Authorized JavaScript origins and your domain's /__/auth/handler address to Authorized redirect URIs. Those errors are the second list talking, not Firebase's.

One fix, every Friday.

One real error, explained in plain English, with the fix — in your inbox every Friday. No spam, no jargon, unsubscribe anytime. Every issue closes with a verse and a word of encouragement.