Docs
Kifuliiru.com
Applications
Kifuliiru.com
Overview
IntroductionArchitectureDevelopment setup
Design languageCalculatorNumbers systemMath question templatesTranslation systemRole-based access controlAudio systemAPI implementation plan
Platform integration
HomeBrowse applications

© 2026 Wekify LLC · Kifuliiru Lab

Homellms.txtkifuliiru.com

GuidesRole-based access control

Role-based access control

User permissions on the portal.

This document explains the role-based access control system implemented for the Kifuliiru website's chat functionality.

Overview

The system controls access to the chat dashboard based on user roles stored in the profiles table. Only users with admin or super_admin roles can access the live chat dashboard.

User Roles

1. New User

  • Condition: User exists in Supabase Auth but not in the profiles table
  • Access: Normal chat only
  • Dashboard: Hidden

2. Viewer

  • Condition: User has role: 'viewer' in profiles table
  • Access: Normal chat only
  • Dashboard: Hidden

3. Contributor

  • Condition: User has role: 'contributor' in profiles table
  • Access: Normal chat only
  • Dashboard: Hidden

4. Admin

  • Condition: User has role: 'admin' in profiles table
  • Access: Normal chat + Live chat dashboard
  • Dashboard: Visible and accessible

5. Super Admin

  • Condition: User has role: 'super_admin' in profiles table
  • Access: Normal chat + Live chat dashboard
  • Dashboard: Visible and accessible

Implementation Details

API Endpoint

  • Route: /api/user/role
  • Method: GET
  • Parameters: userId (query parameter)
  • Returns: Role information and access permissions

Database Schema

The system uses the existing profiles table with a role field:

Code
profiles {
 id: string (primary key)
 role: string ('viewer', 'contributor', 'admin', 'super_admin')
 -- other profile fields
}
```text

### Frontend Integration
- **AuthContext**: Extended to include `roleInfo` and `checkUserRole()` function
- **Chat Component**: Conditionally shows dashboard button based on `canAccessChatDashboard(roleInfo)`
- **Utility Functions**: `roleUtils.ts` provides helper functions for role checking

## Usage Examples

### Checking User Access
```typescript
import { canAccessChatDashboard, getRoleDisplayName } from '@/lib/roleUtils';

// Check if user can access dashboard
if (canAccessChatDashboard(roleInfo)) {
 // Show dashboard button
}

// Get user-friendly role name
const roleName = getRoleDisplayName(roleInfo.role);
```text

### Updating User Role
To grant admin access to a user, update their profile in the database:
```sql
UPDATE profiles 
SET role = 'admin' 
WHERE id = 'user-uuid-here';
```text

## Security Considerations

1. **API Protection**: The role checking API should be protected with proper authentication
2. **Database Security**: Ensure proper RLS (Row Level Security) policies are in place
3. **Role Validation**: Always validate roles on the server side, not just client side
4. **Audit Logging**: Consider logging role changes and dashboard access

## Testing

To test the role-based access control:

1. **New User**: Create a user account and verify dashboard is hidden
2. **Viewer Role**: Set user role to 'viewer' and verify dashboard is hidden
3. **Admin Role**: Set user role to 'admin' and verify dashboard is visible
4. **Super Admin Role**: Set user role to 'super_admin' and verify dashboard is visible

## Future Enhancements

- Add role management UI for administrators
- Implement role-based permissions for other features
- Add audit logging for role changes
- Create role hierarchy system with inheritance
PreviousTranslation systemNextAudio system

On this page

  • Overview
  • User Roles
  • 1. New User
  • 2. Viewer
  • 3. Contributor
  • 4. Admin
  • 5. Super Admin
  • Implementation Details
  • API Endpoint
  • Database Schema