Thomas Osayi

November 22, 2026 · 9 min read · Thomas Osayi

Firebase auth/unauthorized-domain: how to fix it on Vercel, previews and custom domains

Getting Firebase: Error (auth/unauthorized-domain) on Google sign-in? Add the right authorized domains, handle Vercel preview URLs and custom domains, and set authDomain.

You click "Continue with Google" on your newly deployed app and nothing happens, or a popup flashes and closes. The console shows "FirebaseError: Firebase: Error (auth/unauthorized-domain)." Often there is also an earlier info message: "The current domain is not authorized for OAuth operations. This will prevent signInWithPopup, signInWithRedirect, linkWithPopup and linkWithRedirect from working. Add your domain to the OAuth redirect domains list in the Firebase console."

It worked on localhost. It worked on the builder's preview. It fails on the live site, or on a Vercel preview link you sent to a client. The cause is nearly always a missing entry in one settings list, and the fix takes a few minutes once you know which hostname to add. The harder cases involve preview URLs and custom authDomain setups, so I cover those too.

What does auth/unauthorized-domain mean in Firebase?

It means the hostname your app is running on is not in your Firebase project's list of authorized domains, so Firebase refuses to run the OAuth sign-in.

Firebase Authentication only completes OAuth flows, such as Google, Apple, GitHub or Microsoft sign-in, for domains you have approved. Firebase's help page on OAuth redirect domains says you must authorize the domains Firebase can redirect to after sign-in, that localhost and your project's hosting domain are authorized by default, and that you must add the full domain names of any other hosts. Once a domain is on the list, any URL and port on it is allowed.

The Firebase Auth troubleshooting page shows the related message "This domain YOUR_REDIRECT_DOMAIN is not authorized to run this operation," and lists the likely cause as the domain not being an authorized domain, or an invalid API key.

Email and password sign-in does not go through this check, which is why some apps work for password users and fail only on the Google button.

Why does it work on localhost but fail in production?

Because localhost was on the list and your production domain was not, which is exactly how a new project starts.

Ranked by how often I find them:

  • The production domain was never added. The app moved from a builder's preview to Vercel or a custom domain and nobody updated Firebase.
  • Only one of www and the bare domain was added. Firebase treats them as separate hostnames.
  • The user is on a Vercel deployment URL that changes every commit.
  • The domain was entered with https:// or a trailing path, so it does not match the hostname.
  • The app is pointing at a different Firebase project than the one you edited, usually because NEXT_PUBLIC_FIREBASE_PROJECT_ID or VITE_FIREBASE_AUTH_DOMAIN differs between environments.

There is also a newer twist. The Firebase troubleshooting page notes that for projects created after April 28, 2025, Firebase Authentication no longer includes localhost as an authorized domain by default. If your project is newer than that, you may see this error locally too, and need to add localhost yourself for development.

How do I add my domain to the authorized domains list?

Open the Firebase console, go to Authentication, then the Settings tab, then Authorized domains, and add each hostname users sign in from.

Step by step:

  • Go to the Firebase console and select the project your app actually uses. Check the projectId in your Firebase config to be sure.
  • Open Authentication from the left menu, then the Settings tab.
  • Choose Authorized domains and click Add domain.
  • Enter the hostname only: www.yourapp.com, not https://www.yourapp.com/login.
  • Add the bare domain as a separate entry if it also serves the app.
  • Save, then hard refresh the app and try sign-in again.

The change usually takes effect within moments. If it still fails, open DevTools and confirm the exact hostname in the address bar. Typos, a hyphen in the wrong place, or a regional subdomain are common.

How do I handle Vercel preview deployments?

Authorize a stable hostname for previews, because every Vercel commit gets its own URL and Firebase needs full domain names.

According to the Vercel docs on generated URLs, each commit deployment gets a URL made of the project name, a random hash and your team slug on vercel.app. That changes on every push, so authorizing one is pointless. Firebase's help page asks for full domain names, so you cannot rely on a wildcard covering them.

Your options:

  • Use the branch URL. Vercel also creates a URL in the form project-name, then -git-, then the branch name, then your team slug, on vercel.app. It points to the latest deployment on that branch and stays the same across commits. Authorize the branch URL for staging or a long-lived feature branch, and share that link instead of the commit link.
  • Use a custom domain for previews. Assign something like staging.yourapp.com to your preview branch in Vercel and authorize that once.
  • Use a separate Firebase project for previews. Point Preview environment variables at a staging Firebase project, which also keeps test users out of production. My post "Environment variables undefined on Vercel? Every cause and fix" explains how to scope variables per environment.

LACEUP, the basketball apparel storefront I built, runs on a vercel.app domain with a Firebase admin, which is the kind of setup where the deployed hostname has to be on this list before any admin can sign in.

The LACEUP storefront hero, "Built for the run," on its vercel.app domain
The LACEUP storefront hero, "Built for the run," on its vercel.app domain

What do I need to do for a custom domain?

Add both the apex and www hostnames to Authorized domains, and decide whether authDomain should stay on firebaseapp.com or move to your domain.

For most apps, the only change needed is the authorized domains list. Your Firebase config keeps authDomain as your-project-id.firebaseapp.com, sign-in popups open on that domain, and everything works.

Some redirect flows need more. The Firebase guide on redirect best practices explains that browsers blocking third-party storage access can break signInWithRedirect when the app and authDomain are on different domains. Apps on Firebase Hosting under the default firebaseapp.com subdomain are not affected. For everything else, the guide lists options, including:

  • Switching to signInWithPopup, which avoids the redirect flow, with the caveat that popups are sometimes blocked, especially on mobile.
  • Setting authDomain to your own app domain, when that domain is served by Firebase Hosting in the same project.
  • Proxying requests for the /__/auth/ path on your domain to your project's firebaseapp.com domain. The guide warns this must be transparent forwarding, not a 302 redirect. On Vercel or Next.js this is a rewrite rule.
  • Self-hosting the auth helper files, which the guide says does not work for Apple sign-in or SAML.

What happens if I change authDomain?

You also have to add your domain's auth handler URL to your OAuth provider, or you trade one error for another.

When authDomain points at your own domain, the OAuth provider redirects back to https://yourdomain.com/__/auth/handler. The Firebase guide stresses that the trailing /__/auth/handler part is important. For Google sign-in, add that exact URL to Authorized redirect URIs on the OAuth client in Google Cloud, or Google shows "Error 400: redirect_uri_mismatch." Confirm the domain is also in Firebase Authorized domains.

Two more checks:

  • Make sure the authDomain environment variable is set in every Vercel environment. An undefined authDomain produces confusing errors that look unrelated.
  • If you use Firebase Hosting, redeploy so /__/firebase/init.json matches your current config, as the guide notes.

How do I check which Firebase project and authDomain my app is actually using?

Read the config the deployed app is really running with, because editing the right list in the wrong Firebase project is one of the most common reasons the error survives a fix.

AI builders often create a new Firebase project during setup, and later prompts or a teammate create another. The Firebase console shows whichever project you last opened, not the one your live site uses. So before changing settings, confirm the target:

  • Open your deployed site, open DevTools, and in the Sources or Network tab search the loaded JavaScript for firebaseapp.com. The value you find is the authDomain the build is using, and its first part is usually the project ID.
  • Compare it with the project ID shown under Project settings in the Firebase console.
  • Check your environment variables in Vercel for each environment. A Preview environment pointing at one project and Production at another is fine, as long as each project has its own authorized domains.
  • Remember that public Firebase values are baked into the build, so after changing them you must redeploy before the live site picks them up.

If the authDomain in the bundle reads undefined, the error you see may not be about domains at all. Fix the missing variable first, then retest sign-in.

It affects OAuth popup and redirect flows directly, and email link sign-in has a similar domain check on the link it sends users back to.

Email and password sign-in does not open an OAuth flow, so it keeps working while Google sign-in fails. Email link (passwordless) sign-in is different: the continue URL you pass in the action code settings must be on an authorized domain as well, so the same missing entry can break magic links on a new domain. Password reset and email verification links that send users back to your app follow the same idea. When you add a domain for Google sign-in, test the email flows on that domain too.

A worked example: a studio's member portal on a new domain

Here is an illustration with a made-up business. A yoga studio's member portal, built with an AI tool on Firebase, moves from the builder's preview to Vercel on yogastudio.com. Google sign-in fails with auth/unauthorized-domain.

What I check and change:

  • Authorized domains lists localhost and the firebaseapp.com domain only. I add yogastudio.com and www.yogastudio.com.
  • The owner tests on Vercel commit URLs. I add a staging branch, assign staging.yogastudio.com to it, and authorize that.
  • Safari users on the redirect flow get bounced back signed out. Rather than proxy the auth path, I switch desktop sign-in to signInWithPopup and keep authDomain on firebaseapp.com.
  • The Vercel Preview environment used the production Firebase config. I point it at a staging Firebase project.

Under two hours including testing on Chrome, Safari and a phone.

The bottom line

Firebase auth/unauthorized-domain means the hostname in the address bar is not on your authorized list. Add every production hostname, both www and the bare domain, under Authentication, Settings, Authorized domains, using hostnames only. For Vercel previews, authorize a stable branch URL or a custom preview domain rather than commit URLs. Leave authDomain on firebaseapp.com unless you need the redirect flow on browsers that block third-party storage, and if you change it, add the /__/auth/handler URL to your OAuth provider. If sign-in still fails after that, the problem is usually in your Firebase config or environment variables, which I cover in "Firebase Authentication in the Next.js App Router: how to do it properly," and which my Quick Fix from $60 is built for.

Questions, answered in one line

What causes auth/unauthorized-domain in Firebase?

The page calling signInWithPopup or signInWithRedirect is on a hostname that is not listed in Authorized domains under Authentication, Settings in the Firebase console.

How do I add an authorized domain in Firebase?

Open the Firebase console, go to Authentication, then Settings, then Authorized domains, click Add domain and enter the hostname only, such as www.yourapp.com.

Why does Firebase sign-in fail on Vercel preview deployments?

Each Vercel commit deployment has a unique URL, and Firebase requires full domain names, so you need to authorize a stable branch URL or a custom preview domain.

Do I need to add both www and the root domain to Firebase?

Yes, if users can reach the app on both, because Firebase treats www.yourapp.com and yourapp.com as separate domains.

Should I change authDomain to my custom domain?

Only if you also serve the Firebase auth handler on that domain through Firebase Hosting or a proxy and add its handler URL to your OAuth provider, otherwise keep the default firebaseapp.com value.

Who can fix Firebase sign-in on my live domain?

Thomas Osayi fixes one bug like this from $60 in about two days, including authorized domains, OAuth settings and testing on production and previews.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service