Engineering·3 min read

How to Use Firebase Auth Across Multiple Domains Without Whitelisting Every Domain

Whitelisting every domain
Add client domain to Firebase
Add another domain
Forget one, login breaks
Staging URLs always fail
Auth layer approach
Widget triggers your auth domain
Firebase only sees your domain
Token passed back via postMessage
Works on every client site

A simple breakdown of why Firebase authentication fails on embeddable widgets - and how to fix it the right way without turning domain management into a full-time job.

Darshan Vardhan

Darshan Vardhan

Mar 5, 2026

Why this firebase unauthorized domain issue

If you have ever tried to build something embeddable, you have probably hit this wall. Everything works fine on your own website. Then you embed it somewhere else and auth/unauthorized-domain appears. Here is why - and how to fix it properly.

1.Why This Happens

If you have ever tried to build something embeddable, you have probably hit this wall.

Everything works fine on your own website. Then you give your customers a simple script to embed, and suddenly Google login breaks with an error like:

auth/unauthorized-domain

At first it feels like a configuration issue. Maybe you forgot to add a domain. Maybe Firebase is acting up.

But the truth is simpler and more frustrating.

Firebase Authentication checks where the request is coming from. Not where your script is hosted. Not your backend. It checks the actual website where your widget is running.

So if your widget is embedded on a client website, Firebase sees that domain and asks - is this domain allowed? If the answer is no, it blocks the login.

There is no wildcard support. You cannot say allow all domains. That is the core limitation.

2.The Wrong Way to Solve It

A lot of people try this first - add every client domain to Firebase and keep updating the list as new customers come in.

This works for a few users. Then it becomes a mess.

  • You forget to add a domain
  • Customers complain login is broken
  • Preview URLs and staging sites fail
  • You spend time fixing config instead of building product
It does not scale. For a SaaS product, it is a dead end.

3.The Simple Shift That Fixes Everything

The solution is not to fight Firebase.

The solution is to change where authentication happens.

Instead of running Firebase Auth inside the widget, you move it to a domain you control. Think of it as adding a small layer in between.

1

Widget on client site

Triggers login - does not call Firebase directly

2

Your auth domain

auth.yourproduct.com - only place Firebase runs

3

Firebase verifies

Only sees your domain - never the client's

4

Token sent back

postMessage passes token to the widget

4.Step 1 - Use Your Own Domain for Authentication

Set up a dedicated auth page on your domain.

https://auth.yourproduct.com

This is the only place where Firebase runs. In Firebase settings, you only authorize:

  • yourproduct.com
  • auth.yourproduct.com
That is it. No client domains. No scaling issues. Firebase stays inside a boundary you control completely.
Firebase auth domain configuration - only your own domain whitelisted

5.Step 2 - Trigger Login From the Widget

Now your widget becomes simple. When a user clicks Login with Google, instead of calling Firebase directly, it opens your auth page:

https://auth.yourproduct.com/google

This can be a popup or a redirect. At this point, the user is no longer on the client's website.

They are on your domain. Firebase is happy.

6.Step 3 - Authenticate and Generate a Token

Once the user logs in:

  • Firebase verifies the user
  • Your backend creates a session or JWT token
  • This token represents the logged-in user
The token is the handoff point. Everything after this is just API calls - no Firebase dependency on the client side.

7.Step 4 - Send the Token Back to the Widget

Now you pass that token back to the widget using a browser feature called postMessage.

window.opener.postMessage({ token }, '*')

The widget receives the token and stores it. From this point on:

  • The widget does not need Firebase
  • It just sends API requests with the token
  • Simple and clean
postMessage passing the auth token from auth domain back to the embedded widget

8.Why This Works

Because Firebase only ever sees your domain.

It never sees client websites. It never blocks anything. You have created a safe authentication layer that sits between Firebase and the outside world.

  • clientwebsite.com - Firebase never sees it
  • anotherclient.com - Firebase never sees it
  • randomblog.net - Firebase never sees it
If authentication depends on customer domains, your product becomes fragile. If authentication depends on your domain, your product becomes stable.
This is how most serious embeddable SaaS products solve this. Because the alternative simply does not hold up in real usage.

Built this into Widgetkraft from day one.

Widgetkraft's comment chaos widget use exactly this pattern - a dedicated auth layer so Google login works on any customer site without whitelisting a single domain.

If you are building something embeddable and want to see how we structured it, try it on your own site.