Skip to content

Getting started

better-auth-tenancy is a Better Auth plugin that adds multi-tenant authentication to your app.

What it provides

  • A tenant table and CRUD endpoints for tenant management
  • A tenantId column on user, session, account, and verification
  • Tenant-scoped sign-up and sign-in so the same email can exist under different tenants
  • Per-tenant OAuth configuration stored in the database, with fallback to global social providers

Minimal setup

Add the plugin on the server and client:

ts
// auth.ts
import { tenantAuth } from "better-auth-tenancy";
import { betterAuth } from "better-auth";

export const auth = betterAuth({
  // ...database, secret, etc.
  plugins: [tenantAuth()],
});
ts
// auth-client.ts
import { tenantAuthClient } from "better-auth-tenancy/client";
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
  plugins: [tenantAuthClient()],
});

Run the Better Auth CLI to generate or migrate your schema, then create a tenant and sign up a user:

ts
// Create a tenant (requires management access — see Configuration)
await auth.api.createTenant({
  body: { name: "Acme", slug: "acme" },
});

// Sign up under that tenant
await authClient.signUpEmailTenant({
  tenantId: tenant.id,
  email: "user@example.com",
  password: "secure-password",
  name: "Jane Doe",
});

Next steps

Released under the MIT License.