Overview
Trazea implements a secure user management system with an approval workflow to ensure only authorized personnel can access the platform. Every new user must be approved by an administrator before gaining full access to the system.User Registration Flow
The registration process follows these steps:User Signs Up
New users register through Supabase authentication, creating an account with their email and password.
User Record Created
Upon successful authentication, a user record is created in the
usuarios table with:id_usuario: Linked to Supabase auth user IDemail: User’s email addressnombre: User’s full nameactivo: Set totrueby defaultaprobado: Set tofalseinitially (requires admin approval)id_rol: Assigned role ID
Admin Approval Required
The user cannot access the system until an administrator sets
aprobado = true.User Approval Workflow
Implementation Details
The approval system is implemented in the user store:src/entities/user/model/useUserStore.ts:163-166
Session Data Structure
When a user logs in, their session data is fetched from the database:src/shared/api/fetchUserSessionData.ts:31-41
Checking User Status
The system provides helper methods to check user status:Role Assignment
Each user is assigned a role that determines their permissions throughout the system.Available Roles
src/entities/user/model/types.ts:6-10
Admin
Full system access including user management, location setup, and system configuration.
Técnico
Technical staff with access to inventory, spare parts, and service operations.
Supervisor
Enhanced permissions for oversight and approval workflows.
Role Structure
Roles are stored in theroles table with this structure:
src/entities/user/model/useUserStore.ts:62-67
Assigning Roles
To assign a role to a user:- Update the
id_rolfield in theusuariostable - The permissions JSON from the role will be automatically loaded on next login
- User must log out and log back in for role changes to take effect
User Data Structure
src/entities/user/model/useUserStore.ts:69-77
Database Tables
usuarios Table
Stores core user information:| Field | Type | Description |
|---|---|---|
id_usuario | uuid | Primary key, linked to Supabase auth |
email | text | User’s email address |
nombre | text | User’s full name |
activo | boolean | Whether user account is active |
aprobado | boolean | Admin approval status |
id_rol | uuid | Foreign key to roles table |
roles Table
Stores role definitions and permissions:| Field | Type | Description |
|---|---|---|
id_rol | uuid | Primary key |
nombre | text | Role name (admin, tecnico, superuser) |
descripcion | text | Role description |
permissions | jsonb | Permissions object (see Permissions & Roles) |
Best Practices
Security Considerations
Security Considerations
- Always verify both
aprobadoandactivostatus before granting access - Use the built-in helper methods
isUserApproved()andisUserActive() - Never bypass the approval workflow for production environments
- Implement additional checks at the route level for sensitive pages
User Onboarding
User Onboarding
- Create a pending approval page to inform users their account is under review
- Send email notifications to admins when new users register
- Provide clear feedback to users about their approval status
- Set up proper role defaults for new users
Role Management
Role Management
- Document your permission structure clearly
- Test role changes in a development environment first
- Keep a backup of role configurations
- Use descriptive role names and descriptions
Related Topics
Permissions & Roles
Learn about the role-based access control system and permission configuration
Multi-Location Setup
Configure user access across multiple workshop locations