npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@compugit/react-rbac

v1.0.0

Published

A comprehensive Role-Based Access Control (RBAC) library for React applications with support for groups, roles, permissions, and protected components

Readme

React RBAC

A comprehensive Role-Based Access Control (RBAC) library for React applications with TypeScript support.

Features

  • 🔐 Complete RBAC System - Users, Groups, Roles, and Permissions
  • 🎯 Protected Components - Route and element-level protection
  • 🪝 Custom Hooks - Easy-to-use React hooks for authorization
  • 🔧 TypeScript Support - Fully typed for better development experience
  • 🎨 Flexible Authorization - Multiple authorization modes (any/all)
  • 🚀 Performance Optimized - Memoized computations and efficient re-renders
  • 📦 Zero Dependencies - Only requires React as peer dependency

Installation

```bash npm install @compugit/react-rbac

or

yarn add @compugit/react-rbac

or

pnpm add @compugit/react-rbac ```

Quick Start

1. Wrap your app with RBACProvider

```tsx import { RBACProvider } from '@compugit/react-rbac'

const loadUser = async () => { const response = await fetch('/api/user') return response.json() }

function App() { return ( ) } ```

2. Use protected components

```tsx import { ProtectedRoute, ProtectedElement, useRBAC } from '@compugit/react-rbac'

function Dashboard() { const { hasPermission, hasRole } = useRBAC()

return ( Dashboard

  {/* Protected by role */}
  <ProtectedElement roles={['admin']}>
    <AdminPanel />
  </ProtectedElement>

  {/* Protected by permission */}
  <ProtectedElement permissions={['write_posts']}>
    <CreatePostButton />
  </ProtectedElement>

  {/* Protected by group */}
  <ProtectedElement groups={['moderators']}>
    <ModerationTools />
  </ProtectedElement>
</div>

) }

// Protected routes function App() { return ( <ProtectedRoute roles={['user']} fallback={}> ) } ```

3. Use authorization hooks

```tsx import { useRBAC, useAuth } from '@compugit/react-rbac'

function MyComponent() { const { user, hasPermission, hasRole, hasGroup, canAccess } = useRBAC()

const { isAuthenticated, login, logout } = useAuth()

if (!isAuthenticated()) { return }

return ( Welcome {user?.name}

  {hasRole('admin') && <AdminControls />}
  {hasPermission('create_post') && <CreatePostButton />}
  {canAccess('users', 'read') && <UsersList />}
</div>

) } ```

API Reference

Components

<RBACProvider>

The main provider component that manages RBAC state.

```tsx <RBACProvider onUserLoad={() => Promise<User | null>} onRefreshUser={() => Promise<User | null>}

{children} ```

<ProtectedRoute>

Protects entire routes based on authorization rules.

```tsx <ProtectedRoute roles={['admin', 'user']} permissions={['read_content']} groups={['staff']} mode="any" // or "all" fallback={} loadingComponent={}

<ProtectedElement>

Protects individual UI elements.

```tsx <ProtectedElement roles={['admin']} permissions={['delete_user']} fallback={Access Denied}

Hooks

useRBAC()

Main hook providing all RBAC functionality.

```tsx const { // State user, loading, error, initialized,

// Computed values userPermissions, userRoles, userGroups,

// Authorization methods hasPermission, hasRole, hasGroup, hasAccess, canAccess, isAuthenticated,

// Actions setUser, clearAuth, refreshUser } = useRBAC() ```

useAuth()

Simplified authentication hook.

```tsx const { user, loading, isAuthenticated, login, logout, refresh } = useAuth() ```

Higher-Order Components

withAuthorization()

HOC for protecting components.

```tsx const ProtectedComponent = withAuthorization(MyComponent, { roles: ['admin'], fallback: AccessDenied, loading: LoadingSpinner }) ```

Types

```tsx interface User { id: string email: string name: string groups: Group[] roles: Role[] permissions: Permission[] }

interface Role { id: string name: string description?: string permissions: Permission[] }

interface Group { id: string name: string description?: string roles: Role[] permissions: Permission[] }

interface Permission { id: string name: string resource: string action: string description?: string } ```

License

This project is licensed under the MIT License - see the LICENSE file for details.