Skip to content

feat(auth): fallback to querying public.org_members in syncDosOrganizations - #30

Merged
JOY (JOY) merged 1 commit into
mainfrom
dev
Aug 24, 2026
Merged

feat(auth): fallback to querying public.org_members in syncDosOrganizations#30
JOY (JOY) merged 1 commit into
mainfrom
dev

Conversation

@JOY

@JOY JOY (JOY) commented Aug 24, 2026

Copy link
Copy Markdown

Summary

  • In syncDosOrganizations, query public.org_members and public.organizations if organizations claim is absent from OIDC payload.

Test plan

  • Tested with auth unit test suite.

Note

Medium Risk
Touches login-time org membership sync and adds a raw SQL join against auth.users by email. Failures are swallowed, so missing tables or query errors will silently skip sync.

Overview
When DOS/OIDC login does not include an organizations claim, syncDosOrganizations now tries to load orgs from public.org_members / public.organizations (joined to auth.users by 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.

…ations when claims are absent

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown

Welcome to Cal.diy, JOY (@JOY)! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@cursor

cursor Bot commented Aug 24, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@JOY
JOY (JOY) merged commit 6131c78 into main Aug 24, 2026
11 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +24 to +30
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}
`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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      `;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant