Skip to content
>_VibeUnstuck

Firebase: Error (auth/unauthorized-domain)

Last verified:

The fix

Firebase: Error (auth/unauthorized-domain): this host is not in Authorized domains. Add it under Authentication. The Google OAuth list is a separate check.

  1. 1

    Copy the hostname only

    From the address bar, take the host the page is actually on. No https://, no path, no query. my-app.vercel.app and localhost are different entries. Add the preview host you are signing in from. Do not add a host you are not using.

  2. 2

    Add it under Authorized domains

    In the Firebase console, go to Security, then Authentication, then the Settings tab. In the Authorized domains section, click Add domain, and add that hostname. The email-link guide uses those labels. For a project created after April 28, 2025, localhost is not already there. Add it only if you sign in locally. The FAQ says not to leave localhost authorized on a production project you do not want reachable from someone else's machine.

  3. 3

    If authDomain is a custom domain, allow the handler URL

    The Google sign-in guide says to add the custom domain (its example is auth.custom.domain.com) to the authorized domains list, and to allow https://auth.custom.domain.com/__/auth/handler on the OAuth provider's setup page. The authDomain field in the Firebase config has to be that same domain. The default authDomain is <project-id>.firebaseapp.com. Do not change the other config fields to get past this error.

    const firebaseConfig = {
      apiKey: "<api-key>",
      authDomain: "auth.custom.domain.com",
      projectId: "<project-id>",
    };
  4. 4

    Sign in again and read the code

    Save the domain, then run the sign-in again. Keep the catch and read error.code. If it is still auth/unauthorized-domain, the host you added is not the host the page is on. If the code changed, stop and match the new code. Do not replace the catch with an empty one, and do not switch the app to a Supabase client to hide a Firebase domain error.

Why it happens

The Firebase JS auth error reference describes auth/unauthorized-domain as: the app domain is not authorized for OAuth operations for your Firebase project, and you edit the authorized domains from the Firebase console. The hostname in the address bar (a custom domain, a preview host, or localhost) is not on that list. The email-link guide's path is Security, then Authentication, then the Settings tab, then the Authorized domains section, then Add domain.

The authentication FAQ says projects created after April 28, 2025 do not include localhost by default. You add it yourself from that Settings tab if you still sign in on your machine. The Google sign-in guide says a custom authDomain also has to be in the authorized domains list, and that the OAuth setup page has to allow the redirect handler https://<authDomain>/__/auth/handler. This is not a Supabase redirect allow list, and it is not a middleware redirect loop. Those keep the user bouncing. This error stops on the domain check.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Error 400: redirect_uri_mismatch. Google rejected the OAuth request because the redirect_uri it received is not one of the Authorized redirect URIs on that OAuth client. The deployed domain and the callback URL are different strings.

Prompt to paste back into your AI tool

Paste this above the error.

Firebase Auth throws Firebase: Error (auth/unauthorized-domain). The hostname in the address bar is <hostname>. authDomain in the config is <authDomain or the default firebaseapp.com host>.

Do not empty-catch the error. Do not disable App Check, authorized domains, or any security rule to skip the check. Do not put a service account or private key in NEXT_PUBLIC_ or VITE_. Do not swap this project for a Supabase client.

1. Tell me to add this exact hostname under Security > Authentication > Settings > Authorized domains > Add domain. No scheme and no path.
2. If the project was created after April 28, 2025, localhost is not authorized by default. Add it only for local sign-in.
3. If authDomain is a custom domain, tell me to add that domain too, and to allow https://<authDomain>/__/auth/handler on the OAuth provider. Do not invent extra OAuth field names.
4. Show the sign-in call and the catch that prints error.code. Change only the config if authDomain is wrong.
5. Do not rewrite the rest of the app.

Common questions

+Sign-in works on localhost and fails on the deployed URL. Why?

Authorized domains are exact hosts. localhost being allowed does not allow a vercel.app, netlify.app, lovable.app, or custom host. Add the host from the address bar. Projects created after April 28, 2025 do not even include localhost until you add it.

+I added my app URL on the Google OAuth client and it still says unauthorized-domain. Why?

auth/unauthorized-domain is Firebase's authorized-domains list, under Authentication settings. The Google sign-in guide separately tells you to allow https://<authDomain>/__/auth/handler when authDomain is a custom domain. The app's own page URL is not that handler.

Related errors