Multi-Tenant Authentication Issue: User Login Conflicts with Same Email Across Different Tenants
I'm building a multi-tenant application using Better Auth with a single database approach. I'm using tenant_id to separate data between organizations. However, I'm facing a critical authentication issue when users belong to multiple organizations.
The Issue
When a user with the same email exists in multiple tenants (organizations), Better Auth's internal user lookup logic appears to randomly select one of the user records during login:
What I need:
John tries to login to Organization A's portal
Better Auth finds both user records but randomly picks one
John might get logged in as the Organization B user instead
so how solve this issue ?
The Issue
When a user with the same email exists in multiple tenants (organizations), Better Auth's internal user lookup logic appears to randomly select one of the user records during login:
What I need:
John tries to login to Organization A's portal
Better Auth finds both user records but randomly picks one
John might get logged in as the Organization B user instead
so how solve this issue ?