Skip to content

Non deterministic Active Org selection on sign-in #38

Description

@skools-here

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions