Reusables

Permission

Role-based permission system for managing user access control

Overview

A lightweight permission system that:

  • Defines roles with specific permissions
  • Checks if users have access to certain actions
  • Uses a simple role:action permission format

Installation

npx shadcn@latest add "https://reusables.vercel.app/r/permission"

Usage

Define your role-based permissions:

//This will be from backend
 
const user = {
  id: "user_123",
  authorisation: "admin", // Must match a role from ROLES
}

Check Permissions

function Example() {
  // Simple permission check
  const canUpdate = hasPermission(user, "update:blog")
 
  return (
    <div>
      {canUpdate ?
        <button>Update Blog</button>
      : <p>No permission to delete</p>}
    </div>
  )
}
Edit on GitHub

Last updated on 2/4/2025

On this page