fix(auth): sort org memberships by creation date#1268
Conversation
…ected by default When activeOrganizationId is unset, findFirst() returned whichever membership the database happened to return first (typically oldest). This caused users to be signed into older test orgs instead of their primary org.
📝 WalkthroughWalkthroughThis PR adds deterministic ordering to membership queries by importing the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
orderBy: desc(members.createdAt)to membership queries so the most recently created org is selected by default when no active org is set on the sessionChanges
packages/auth/src/server.ts—customSessionplugin now picks newest membership firstpackages/trpc/src/router/user/user.ts—myOrganizationandmyOrganizationsboth return orgs newest-firstTest plan
Summary by CodeRabbit
Release Notes