Better Auth + Multi-Tenant (Separate DBs per tenant)

Hey everyone, Seeking advice on integrating Better Auth in a multi-tenant app where each tenant has its own Postgres DB. My current idea involves using Better Auth's hooks.before to dynamically create a prismaAdapter with the tenant-specific PrismaClient by modifying ctx.context.adapter. Is this a sound approach, or are there better/recommended ways to pass a dynamic Prisma instance to Better Auth per request? Also, any potential pitfalls or edge cases I should be aware of with this method? Open to all suggestions!
2 Replies
Ping
Ping3w ago
Any reason why you can't have 1 db for better auth, and leave all other dbs for your tennets to use?
Amit
AmitOP3w ago
Because for our use case, users are strictly scoped to a single tenant and there is no concept of 'global' user that can access multiple tenant

Did you find this page helpful?