Blog
7 min read

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. localhost covers localhost:5173 and localhost:3000.
  • localhost and 127.0.0.1 are different. IP addresses must match exactly, so if you open your dev server at http://127.0.0.1:5173, add 127.0.0.1 too, or use localhost.
  • An entry also covers its subdomains in the SDK's check: example.com matches www.example.com. www.example.com doesn't match example.com.
  • Only http and https pages 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

  1. Open the Firebase console and select the right project.
  2. Go to Authentication, then the Settings tab.
  3. Under Authorized domains, click Add domain.
  4. 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.

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

  1. Run location.hostname on the failing page.
  2. Firebase console > Authentication > Settings > Authorized domains > Add domain, hostname only.
  3. Confirm the console project matches projectId in the config your app loads.
  4. Using 127.0.0.1? Add it too, or switch to localhost.
  5. New project (after 28 April 2025)? Add localhost in a development project, not production.
  6. Using signInWithRedirect off Firebase Hosting? Switch to a popup, or set authDomain to 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