Overview
Quality Hub GINEZ uses Supabase Authentication for secure user management. The authentication system includes session management, profile synchronization, approval workflows, and role-based access control.Authentication Architecture
Components
The authentication system consists of three main components:- AuthProvider - React context provider for auth state management
- Supabase Auth - Backend authentication service
- Profiles Table - User metadata and role information
Data Flow
AuthProvider Implementation
TheAuthProvider component manages authentication state across the application.
Interface Definition
Core Features
Session Management
The provider checks for active sessions on initialization:Profile Fetching
Profile data is retrieved from theprofiles table:
Approval Check
Users must be approved to access the system:Auth State Changes
Real-time authentication state monitoring:Usage
Permissions System
The permissions system is built on top of authentication using theusePermissions hook.
Permission Types
usePermissions Hook
The hook fetches permissions based on the user’s role:Permission Check Functions
Access Level Checks
Specific Permission Checks
Filter and Tab Checks
Implementation Examples
Conditional Rendering Based on Access
Conditional Filters
Conditional Tabs
Action Buttons Based on Permissions
Database Functions
get_user_permissions_v2
SQL function that retrieves permissions based on user role:Registration Flow
New User Registration
-
User fills registration form with:
- Full name
- Password
- Role selection
- Branch selection
-
Account created in
auth.users -
Profile created in
profilestable withapproved = false - User redirected to pending approval page
Administrator Approval
- Admin navigates to Configuration → Users
- Pending users shown with amber badge
- Admin clicks Approve button
- User can now log in and access the system
Automatic Permission Assignment
Permissions are automatically assigned based on the selected role. No manual permission configuration is required.Sign Out Flow
Security Best Practices
Row Level Security (RLS)
Supabase RLS policies control data access:Protected Routes
Pages check authentication status:Session Persistence
Sessions are persisted in browser storage and automatically refreshed.Error Handling
Session Errors
Abort errors in development mode are safely ignored:Profile Fetch Errors
Profile fetch failures are logged but don’t crash the app:Testing Authentication
Check Current User
Check Permissions
Troubleshooting
User Cannot Log In
- Check if user is approved in
profilestable - Verify email/password are correct
- Check browser console for auth errors
Permissions Not Loading
- Verify user has a role assigned in
profilestable - Check that role exists in
user_roles_v2table - Verify permissions exist in
module_access_levelsfor that role
Session Expired
Sessions are automatically refreshed. If issues persist:- Clear browser cache and cookies
- Log out and log back in
- Check Supabase session configuration
