Conversation
…ations when claims are absent Co-authored-by: Cursor <cursoragent@cursor.com>
|
Welcome to Cal.diy, JOY (@JOY)! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_4b4e8dce-449f-4287-a817-196dbb15b6d6) |
There was a problem hiding this comment.
Code Review
This pull request updates the syncDosOrganizations function to fallback to querying the database for organizations associated with the user's email if the organizations argument is empty or missing. The feedback suggests making the SQL email comparison case-insensitive using LOWER() to ensure robustness against mixed-case emails.
| const dbOrgs = await prisma.$queryRaw<DosOrgClaim[]>` | ||
| SELECT om.org_id as id, o.name, o.slug, om.role | ||
| FROM public.org_members om | ||
| JOIN public.organizations o ON om.org_id = o.id | ||
| JOIN auth.users u ON om.user_id = u.id | ||
| WHERE u.email = ${user.email} | ||
| `; |
There was a problem hiding this comment.
Email comparisons in SQL should be case-insensitive to prevent issues where users with mixed-case emails fail to sync their organizations. Using LOWER() on both sides of the comparison ensures robustness.
const dbOrgs = await prisma.$queryRaw<DosOrgClaim[]>`\n SELECT om.org_id as id, o.name, o.slug, om.role\n FROM public.org_members om\n JOIN public.organizations o ON om.org_id = o.id\n JOIN auth.users u ON om.user_id = u.id\n WHERE LOWER(u.email) = LOWER(${user.email})\n `;
Summary
Test plan
Note
Medium Risk
Touches login-time org membership sync and adds a raw SQL join against
auth.usersby email. Failures are swallowed, so missing tables or query errors will silently skip sync.Overview
When DOS/OIDC login does not include an
organizationsclaim,syncDosOrganizationsnow tries to load orgs frompublic.org_members/public.organizations(joined toauth.usersby email) before giving up.The existing team/membership/profile upsert path is unchanged. Query errors are ignored so environments without those tables still no-op.
Reviewed by Cursor Bugbot for commit d920750. Bugbot is set up for automated code reviews on this repo. Configure here.