Skip to the content.

React Auth Gate

A production-grade React authorization framework that centralizes RBAC, PBAC, ABAC, feature flags, and async permission checks into a clean, declarative API.

npm version License: MIT


✨ Features


🎮 Live Demo

Check out TaskFlow - A full-featured task management app built with react-auth-gate:

👉 View Demo Source Code

The demo showcases:


🚀 Quick Start

Installation

npm install react-auth-gate

Basic Usage

import { PermissionsRoot, PermissionsGate, usePermission } from 'react-auth-gate';

const rules = {
  'admin.access': ({ roles }) => roles.includes('admin'),
  'post.edit': ({ user, resource }) => resource.authorId === user.id,
};

function App() {
  return (
    <PermissionsRoot user={currentUser} roles={['editor']} rules={rules}>
      <PermissionsGate allow="admin.access">
        <AdminPanel />
      </PermissionsGate>
      
      <PermissionsGate allow="post.edit" resource={post}>
        <EditButton />
      </PermissionsGate>
    </PermissionsRoot>
  );
}

📚 Core Components

<PermissionsRoot>

Wrapper provider that automatically integrates dev tools in development.

<PermissionsRoot
  user={currentUser}
  roles={['admin', 'editor']}
  permissions={['post.edit', 'post.delete']}
  rules={customRules}
  flags=
>
  <App />
</PermissionsRoot>

<PermissionsGate>

Conditional rendering based on permissions.

<PermissionsGate 
  allow="post.edit" 
  resource={post}
  fallback={<DisabledButton />}
>
  <EditButton />
</PermissionsGate>

usePermission() Hook

Programmatic permission checks.

const { allowed, loading } = usePermission('post.edit', post);

if (loading) return <Spinner />;

return (
  <button disabled={!allowed}>
    Edit Post
  </button>
);

🎛️ Dev Tools Panel

The built-in dev panel lets you:

Automatically enabled in development mode!

Screenshots

Evaluations Tab - See all permission checks in real-time:

Dev Panel Evaluations

Overrides Tab - Override roles, permissions, and feature flags:

Dev Panel Overrides

Context Tab - View current user context:

Dev Panel Context


📖 Documentation



📝 License

MIT © Klejdi 2K