-->
Learn when multi-tenancy is needed, common pitfalls with Firebase Auth, how to implement it in TypeScript, and how Fuego streamlines tenant and user management.
Managing multiple sets of users in a single application is a common requirement in SaaS platforms, B2B solutions, and enterprise applications. Firebase Authentication provides native support for multi-tenancy, but the implementation and ongoing management can be more challenging than it first appears.
In this post, we’ll look at when multi-tenancy is useful, what problems developers usually encounter, how to implement it with TypeScript, and how tools like Fuego can simplify the day-to-day management of tenants and their users.
Multi-tenancy allows you to logically separate users into groups (tenants) while still using a single Firebase project. This is particularly useful in cases like:
While Firebase Auth supports tenants, developers often face a few difficulties:
Limited Google Console features
User migration
Consistent data handling
Testing and emulators
Before writing code, turn on multi‑tenancy and create at least one tenant:
Once enabled and configured, you can select the active tenant in your client by setting auth.tenantId
.
Identity Platform/Firebase Auth supports multi-tenancy directly from the client. The key is setting auth.tenantId
before you call any sign-in / sign-up method. Note that tenantId
is not persisted across page reloads, so you must set it each time you need it.
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const app = initializeApp({
apiKey: "…",
authDomain: "YOUR_CUSTOM_DOMAIN", // optional custom domain
});
const auth = getAuth(app);
// Choose the active tenant for the next auth operations
auth.tenantId = "TENANT_ID1";
import {
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
} from "firebase/auth";
// Ensure the intended tenant is selected
auth.tenantId = "TENANT_ID1";
// Sign up (account will belong to TENANT_ID1)
await createUserWithEmailAndPassword(auth, "user@acme.com", "StrongPass#123");
// Sign in
const { user } = await signInWithEmailAndPassword(
auth,
"user@acme.com",
"StrongPass#123",
);
console.log(user.tenantId); // => "TENANT_ID1"
Auth
instance// Switch to another tenant for subsequent calls
auth.tenantId = "TENANT_ID2";
// Switch back to project-level IdPs (no tenant)
auth.tenantId = null;
Auth
instances (one per tenant)import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const app1 = initializeApp(
{
/* same config */
},
"app_tenant1",
);
const app2 = initializeApp(
{
/* same config */
},
"app_tenant2",
);
const auth1 = getAuth(app1);
auth1.tenantId = "TENANT_ID1";
const auth2 = getAuth(app2);
auth2.tenantId = "TENANT_ID2";
import { signInWithCustomToken } from "firebase/auth";
auth.tenantId = "TENANT_ID1";
await signInWithCustomToken(auth, SOME_CUSTOM_TOKEN_FOR_TENANT_ID1);
import { sendPasswordResetEmail } from "firebase/auth";
// Make sure the correct tenant is selected, otherwise the email action will fail or target the wrong tenant
auth.tenantId = "TENANT_ID1";
await sendPasswordResetEmail(auth, "user@acme.com");
import { OAuthProvider, signInWithPopup } from "firebase/auth";
auth.tenantId = "TENANT_ID1";
const provider = new OAuthProvider("microsoft.com");
const result = await signInWithPopup(auth, provider);
console.log(result.user.tenantId); // "TENANT_ID1"
Tip: after you sign a user in on tenant A, changing
auth.tenantId
later does not changeauth.currentUser.tenantId
; the current session remains linked to the original tenant until you sign out.
While the Firebase console provides a UI for managing users, its multi-tenant features are limited:
This means that for anything beyond simple user creation, you’ll need custom scripts—or a dedicated tool.
For developers and teams that actively manage multi-tenant applications, Fuego provides a much smoother workflow:
This means less time fighting the console and more time focusing on your application.
Multi-tenancy is essential for many SaaS and enterprise apps, and Firebase Auth provides the foundation to support it. But real-world use quickly reveals gaps in the tooling and console.
By combining the Firebase Admin SDK with a management tool like Fuego, you can implement, maintain, and scale multi-tenant user bases far more effectively.