Role-Based Access Control (RBAC)

Granular permission system with role definitions, permission mapping, route protection, and component-level authorization.

What's Included#

  • Role and permission type definitions (USER, ADMIN, SUPER_ADMIN)
  • Permission-to-role mapping with type-safe checks
  • Server-side permission guards (hasPermission, requirePermission, withRole)
  • Component-level conditional rendering based on role
  • API route and server action protection
  • Middleware-based route authorization
  • Role-based navigation rendering
  • Client-side useRole hook for role checks
  • Prisma schema with Role enum

Usage#

Via CLI#

Loading code block...

Via AI Assistant#

Ask your AI assistant:

  • "Use the RBAC pattern from Bootspring"
  • "Apply the Bootspring role-based access control pattern to my project"

Key Considerations#

  • Check permissions rather than roles directly for more flexible access control
  • Default to least privilege so new users start with minimal permissions
  • Centralize authorization logic in a single module as the source of truth
  • Audit all role changes and permission modifications
  • Use TypeScript enums for type-safe role definitions