c/backend › command
0votes

Role-Based Access Control

PromptLow risk
submitted by CommandVault editors to c/backend · 5 uses

Limit sensitive features to the right people

Prompt · 2 variables
Add role-based access control.

Stack: {{stack}}
Roles and permissions: {{goal}}

Requirements:
1. Define the roles and permissions above in one place in code, and check permissions (not role names) at each use.
2. Enforce access on the server for every protected page, API route and mutation. Hiding buttons in the UI is not enough.
3. Deny by default: new routes are blocked until they declare the permission they need.
4. Return 403 (not 404 or 500) for authenticated users without permission, and log the denial.
5. Keep roles somewhere the client can't edit (server-side session or database), and make role changes take effect on the next request.

List the files you'll change, then give me a test matrix: each role against each protected action, with the expected result.
e.g. 'admin: everything; editor: create and edit posts; viewer: read only'
Framework, language and versions, e.g. Next.js 16 App Router + TypeScript
0 commentsreport

Try it here

Fill in {{goal}} above first for a better answer, or run it as is and the AI will assume sensible values.

or open in ChatGPT · Claude · Perplexity

How to use this prompt

  1. Fill in the 2 blanks above. The more specific you are, the better the answer.
  2. Copy it and paste it into ChatGPT, Claude, Gemini, Cursor or Codex, or use "Try it here" for a quick test.
  3. Read the answer critically: check anything it claims about your code or data before you rely on it.
  • {{goal}} e.g. 'admin: everything; editor: create and edit posts; viewer: read only'
  • {{stack}} Framework, language and versions, e.g. Next.js 16 App Router + TypeScript

More from c/backend

See all of c/backend →
0 comments

Log in to join the discussion.