Skip to content

fix: sync WorkOS role to database on login#389

Open
mcarlson wants to merge 1 commit intostagefrom
fix/sync-workos-role-on-login
Open

fix: sync WorkOS role to database on login#389
mcarlson wants to merge 1 commit intostagefrom
fix/sync-workos-role-on-login

Conversation

@mcarlson
Copy link
Copy Markdown
Collaborator

Summary

  • Syncs the user's WorkOS organization role to the database on every authenticated request in setWorkOSUserContext()
  • Previously, roles were only set during signup (via invite code) or through WorkOS webhooks — if a role was changed in WorkOS and the webhook failed or wasn't configured, the DB role stayed stale
  • This makes role sync self-healing: any role change in WorkOS takes effect on the user's next login

Test plan

  • Change a user's role in WorkOS dashboard (e.g. user-group → admin-group)
  • Have the user log in and verify /v2/auth/authenticate returns the updated role
  • Verify the user can access role-gated routes (e.g. /studio for creator-group/admin-group)
  • Verify that if the WorkOS role slug doesn't match any DB role, the user's existing role is preserved (no downgrade)

🤖 Generated with Claude Code

Previously, the user's role was only set in the database during initial
signup (via invite code) or through WorkOS webhooks. If a user's role was
changed in WorkOS and the webhook failed or wasn't configured, the
database role would remain stale. This caused role-gated routes like
/studio to be inaccessible despite the correct role in WorkOS.

Now setWorkOSUserContext() compares the WorkOS organization membership
role with the database role on each authenticated request and updates the
database if they differ, making role sync self-healing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mcarlson mcarlson requested a review from scottdraves March 15, 2026 09:24
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