When a user signs in, the system automatically selects an "active" organization for their session if one isn't already set. This logic resides in apps/api/src/auth.ts within the pickActiveOrgId function.
Currently, it uses Drizzle's findFirst on the orgMembers table without an orderBy clause. In PostgreSQL (and most relational databases), findFirst without an explicit sort order is non-deterministic it typically returns the row that is physically first on disk or determined by the index used for the scan.
For users who are members of multiple organizations, this means their "landing" org after sign-in can change arbitrarily.
When a user signs in, the system automatically selects an "active" organization for their session if one isn't already set. This logic resides in
apps/api/src/auth.tswithin thepickActiveOrgIdfunction.Currently, it uses Drizzle's findFirst on the orgMembers table without an orderBy clause. In PostgreSQL (and most relational databases), findFirst without an explicit sort order is non-deterministic it typically returns the row that is physically first on disk or determined by the index used for the scan.
For users who are members of multiple organizations, this means their "landing" org after sign-in can change arbitrarily.