Add sponsor role feature - gate Create access to sponsors#254
Conversation
|
@Delightech28 is attempting to deploy a commit to the Threadflow Team on Vercel. A member of the Team first needs to authorize it. |
|
@Delightech28 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Warning Review limit reached
More reviews will be available in 36 minutes and 4 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds a sponsor role to the user session and gates bounty creation access. It extends auth types with a role (defaulting to "contributor"), hides the Create navbar link for non-sponsors, protects /bounty/create with a redirect, and adds a settings toggle to switch roles. ChangesSponsor Role Gating and Access Control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Benjtalkshow
left a comment
There was a problem hiding this comment.
The role gating logic is correct: backend validates the role value and defaults to contributor, client inferAdditionalFields makes updateUser type-safe, the navbar and route both check the session, and the settings toggle uses an optimistic update with rollback. All five acceptance criteria are met functionally.
Three things to fix before merge.
The branch is 10 commits behind upstream main. pnpm tsc --noEmit fails on e2e/bounty-creation.spec.ts because PR #248 (which deleted that file) isn't in your branch. Please rebase against upstream/main and the errors go away.
The (session?.user as { role?: string } | undefined)?.role as "sponsor" | "contributor" | undefined cast is duplicated in global-navbar.tsx, app/bounty/create/page.tsx, and components/settings/profile-tab.tsx. Extract it to a single useUserRole() hook that returns the typed role, so callers stop repeating the cast.
/bounty/create renders "Coming soon..." with a TODO comment. The bounty creation form isn't built yet (issue #181 is still open), so a placeholder is fine, but make it look intentional. Replace it with a small card explaining the form is coming, or render null until the form exists. A bare TODO comment in production code reads as unfinished.
Once those three are in, this is ready.
8ce0f3a to
2a833b6
Compare
|
Thanks for the detailed feedback! I've addressed all three issues:
All changes pushed to this branch. Ready for merge! |
Fixes react/no-unescaped-entities lint error introduced in #254.
Add sponsor role to user session and gate Create access
Description
Restricts bounty creation to users with a sponsor role. Previously, any authenticated user could create a bounty. This change implements a role-based access control system with sponsor and contributor roles.
Related Issue
Closes #207
Changes Made
1. Extended User Session Type
role: "sponsor" | "contributor"field to User interfaceinferAdditionalFieldsplugin that's already in placeFiles:
lib/server-auth.ts- Updated User interface and getCurrentUser()lib/auth-client.ts- Added role to inferAdditionalFields pluginhooks/use-user-mutations.ts- Added role to UpdateUserParams2. Gated Navbar Create Link
role === "sponsor"authClient.useSession()to read role from sessionFile:
components/global-navbar.tsx3. Protected Create Route
/bounty/createnow checks user role on mount/bountyFile:
app/bounty/create/page.tsx4. Settings Role Toggle
useUpdateUserMutation()File:
components/settings/profile-tab.tsxAcceptance Criteria
/bounty/createas a contributor redirects to/bounty/bounty/createTesting Checklist
/bounty/create- should redirect to/bountyNotes
closes #207
Summary by CodeRabbit