Skip to content

feat:Replace NEXT_PUBLIC_MOCK_MAINTAINER env flag with useUserRole hook - #303

Merged
Benjtalkshow merged 3 commits into
boundlessfi:mainfrom
Olajcodes:feature/replace-env-flag-with-useUserRolehook
Jun 27, 2026
Merged

feat:Replace NEXT_PUBLIC_MOCK_MAINTAINER env flag with useUserRole hook#303
Benjtalkshow merged 3 commits into
boundlessfi:mainfrom
Olajcodes:feature/replace-env-flag-with-useUserRolehook

Conversation

@Olajcodes

@Olajcodes Olajcodes commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #274.

Replaces the NEXT_PUBLIC_MOCK_MAINTAINER environment flag with the real useUserRole() hook introduced in PR #254. The old constant was a dev shim that bypassed session-based role checks entirely — the console.warn block in the file itself flagged it as something that must never reach production. This PR removes it and wires the sidebar to the actual authenticated session role.


Changes

components/bounty/bounty-sidebar.tsx

Removed:

  • const IS_MAINTAINER = process.env.NEXT_PUBLIC_MOCK_MAINTAINER === "true"; (line 32)
  • The console.warn guard block (lines 34–41) that acknowledged the shim was unsafe for production

Added:

  • import { useUserRole } from "@/hooks/use-user-role";
  • const role = useUserRole(); — reads the role from the live session via authClient.useSession()
  • const isSponsor = role === "sponsor"; — replaces every IS_MAINTAINER reference throughout the component

No other files changed. No new env vars introduced.


Acceptance criteria

  • No reference to NEXT_PUBLIC_MOCK_MAINTAINER remains in bounty-sidebar.tsx
  • Maintainer-only UI (Mark as Completed, rate contributor) is visible to users with the sponsor role and hidden for contributor users
  • No new env vars required
  • console.warn block removed

How to test

Scenario Expected result
Signed in as a sponsor and bounty is IN_PROGRESS "Mark as Completed" button is shown
Signed in as a contributor and bounty is IN_PROGRESS "Mark as Completed" button is hidden; claim/status button shown instead
Not signed in (role === undefined) Maintainer actions are hidden
Sponsor clicks "Mark as Completed" Rating modal opens after simulated API call
Contributor triggers handleMarkCompleted directly (e.g. via devtools) Alert: "Only maintainers can mark as completed."
Rating block shown after rating Text reads "You rated the contributor:" for sponsors, "Contributor was rated:" for others

Diff at a glance

-import { useClaimBounty } from "@/hooks/use-bounty-mutations";
+import { useClaimBounty } from "@/hooks/use-bounty-mutations";
+import { useUserRole } from "@/hooks/use-user-role";
  • // Mock maintainer check for now - in real app this comes from auth context
  • const IS_MAINTAINER = process.env.NEXT_PUBLIC_MOCK_MAINTAINER === "true";
  • if (
  • typeof window !== "undefined" &&
  • process.env.NEXT_PUBLIC_MOCK_MAINTAINER === "true"
  • ) {
  • console.warn(
  •  "DEV: Mock maintainer enabled in components/bounty/bounty-sidebar.tsx — do NOT enable in production",
    
  • );
  • }
  • const role = useUserRole();
  • const isSponsor = role === "sponsor";
  • if (!IS_MAINTAINER) { // handleMarkCompleted
  • if (!isSponsor) {
  • if (!IS_MAINTAINER) { // handleSubmitRating
  • if (!isSponsor) {
  • if (bounty.status === "IN_PROGRESS" && IS_MAINTAINER && !completed) {
  • if (bounty.status === "IN_PROGRESS" && isSponsor && !completed) {
  • {IS_MAINTAINER
  • {isSponsor

Summary by CodeRabbit

  • Bug Fixes
    • Sponsor-only actions now use the signed-in user’s role for access control, improving consistency for marking bounties completed and submitting ratings.
    • The “Mark as Completed” action is shown only for eligible sponsors and only during the correct in-progress bounty state.
    • After submitting a rating, the success/reputation confirmation messaging now reflects the user’s role more accurately.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Olajcodes is attempting to deploy a commit to the Threadflow Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Olajcodes 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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99a096d7-89f3-400c-93a9-8a7fb0c6ab98

📥 Commits

Reviewing files that changed from the base of the PR and between fd4f4f3 and dfd90fd.

📒 Files selected for processing (1)
  • components/bounty/bounty-sidebar.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/bounty/bounty-sidebar.tsx

📝 Walkthrough

Walkthrough

The bounty sidebar now uses useUserRole() to derive sponsor access instead of the mock maintainer env flag. Sponsor-only completion and rating actions, the completion button, and the post-rating message now follow that role check.

Changes

Sponsor role gating

Layer / File(s) Summary
Role hook wiring
components/bounty/bounty-sidebar.tsx
Imports useUserRole and derives isSponsor from the current role instead of the env-based maintainer flag.
Sponsor-gated sidebar actions
components/bounty/bounty-sidebar.tsx
Uses isSponsor to gate mark-completed and rating actions, show the completion button, and switch the post-rating label.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Benjtalkshow

Poem

A rabbit hopped through sidebar light,
and found the sponsor path set right.
No mock flag twitched in the breeze;
role checks now rustle with ease.
Hop-hop — the buttons blink just so.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: replacing the mock maintainer env flag with useUserRole.
Linked Issues check ✅ Passed The sidebar swap to useUserRole, sponsor-role gating, and removal of the env shim and warn block match #274's requirements.
Out of Scope Changes check ✅ Passed Only the bounty sidebar was changed, and the edits stay within the env-flag-to-role-gating scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/bounty/bounty-sidebar.tsx`:
- Around line 85-87: The role-guard copy in bounty-sidebar’s sponsor checks is
stale: the alert text still says “Only maintainers” even though the logic now
uses isSponsor. Update the denial message in the affected guard blocks
(including the repeated check in the same component) to say “Only sponsors can
mark as completed” or equivalent, so the user-facing copy matches the new role
contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b22cb49-f39e-4521-94d6-4a0a111fe96f

📥 Commits

Reviewing files that changed from the base of the PR and between 9e5dc91 and fd4f4f3.

📒 Files selected for processing (1)
  • components/bounty/bounty-sidebar.tsx

Comment thread components/bounty/bounty-sidebar.tsx

@Benjtalkshow Benjtalkshow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean change, all acceptance criteria from #274 are met, CI is green, tsc
and lint pass locally. One small thing: the file lost its trailing newline
("\ No newline at end of file" in the diff) — please add the newline back
on the closing brace so this matches the rest of the codebase. Also please
attach a screenshot showing the bounty sidebar for both a sponsor (Mark as
Completed visible) and a contributor (button hidden) so I can verify the
gating visually. Once those are in, ready to merge.

@Benjtalkshow Benjtalkshow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All addressed cleanly — trailing newline is back and the CodeRabbit feedback is in. Local pnpm lint, pnpm tsc --noEmit, and pnpm build all pass, no NEXT_PUBLIC_MOCK_MAINTAINER or IS_MAINTAINER residue left. Just attach a screenshot of the bounty sidebar for both a sponsor (showing the Mark as Completed button) and a contributor (button hidden) so I can verify the role gating visually, then ready to merge.

@Benjtalkshow
Benjtalkshow merged commit b3ce821 into boundlessfi:main Jun 27, 2026
4 of 5 checks passed
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.

Replace NEXT_PUBLIC_MOCK_MAINTAINER env flag with useUserRole hook

2 participants