Skip to content

klejdi94/demo-react-auth-gate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TaskFlow - Demo App for react-auth-gate

A professional task management dashboard demonstrating the full capabilities of react-auth-gate.

🔗 Library Documentation

Features

This demo showcases:

  • Role-Based Access Control (RBAC) - Admin, Manager, and Member roles
  • Resource-Based Permissions - Users can only edit/delete their own tasks
  • Permission Gates - Conditional rendering based on permissions
  • Dev Tools Panel - Real-time permission debugging and overrides
  • Full CRUD Operations - Create, read, update, delete tasks
  • Statistics Dashboard - Role-restricted analytics

Roles & Permissions

Admin

  • Full access to all features
  • Can view statistics dashboard
  • Can edit and delete any task
  • Can reassign tasks to anyone

Manager

  • Can view statistics dashboard
  • Can edit and delete any task
  • Can reassign tasks to team members
  • Can create tasks

Member

  • Can create tasks
  • Can only edit tasks assigned to them
  • Cannot delete other users' tasks
  • Cannot view statistics dashboard

Running Locally

# Install dependencies
npm install

# Start dev server
npm run dev

The app will run on http://localhost:3011 (or next available port).

Key Implementation Details

Permission Rules

const rules: PermissionRulesMap<User, Task> = {
  'admin.access': ({ roles }) => roles.includes('admin'),
  
  'task.create': ({ roles }) => 
    ['admin', 'manager', 'member'].some(r => roles.includes(r)),
  
  'task.edit': ({ user, resource, roles }) => {
    if (roles.includes('admin')) return true;
    if (roles.includes('manager')) return true;
    return resource?.assigneeId === user.id;
  },
  
  'task.delete': ({ user, resource, roles }) => {
    if (roles.includes('admin')) return true;
    return resource?.createdBy === user.id;
  },
  
  'stats.view': ({ roles }) => 
    roles.includes('admin') || roles.includes('manager'),
};

Using PermissionsRoot

<PermissionsRoot
  user={currentUser}
  roles={userRoles}
  rules={rules}
>
  <App />
</PermissionsRoot>

Conditional Rendering

<PermissionsGate allow="task.edit" resource={task}>
  <button>Edit Task</button>
</PermissionsGate>

Programmatic Checks

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

<button disabled={!allowed}>Edit</button>

Built With

  • react-auth-gate - Authorization framework
  • React 18 - UI library
  • Vite - Build tool
  • TypeScript - Type safety

License

MIT


Built to demonstrate react-auth-gate by Klejdi 2K

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors