User Roles
The system defines two roles inbackend/helpers/constants.ts:
backend/helpers/constants.ts
User Role (50yunUs3r)
This is the default role assigned to all new registrations unless the admin key is provided.
Capabilities:
- Access standard application features
- View their own data
- Create and manage appointments
- Update personal information
- Cannot access administrative endpoints
- Cannot modify other users’ data
- Cannot manage system-wide settings
Admin Role (50yun4dmin)
Administrative users have elevated privileges for managing the platform.
Capabilities:
- All user role capabilities
- Access administrative endpoints
- Manage all users, appointments, and resources
- Configure system settings
- Access analytics and reports
User Model
The user data structure is defined using Sequelize ORM:backend/models/user.ts
Key Fields
- id: Auto-incremented primary key
- name: User’s first name (required)
- surname: User’s last name (required)
- email: Unique identifier for login (required, must be valid email)
- password: Bcrypt-hashed password (required, min 6 characters)
- rol: User role, defaults to standard user
Registration Process
Standard User Registration
backend/controllers/auth.ts
Admin User Registration
To create an admin user, include theadmin-key header:
backend/controllers/auth.ts
Permission Validation
Admin Middleware
Protected administrative routes use theisAdmin middleware:
backend/middlewares/validatorAdmin.ts
Middleware Chain
Admin-protected routes typically use both JWT validation and role checking:Validation Rules
The registration endpoint enforces strict validation rules:backend/routes/auth.ts
Validation Checks
- Name: Required, cannot be empty
- Surname: Required, cannot be empty
- Email: Required, must be valid email format, must not already exist in database
- Password: Required, minimum 6 characters
Error Handling
Registration Errors
Authentication Errors
Best Practices
Password Requirements
Password Requirements
While the system requires minimum 6 characters, implement stronger requirements:
- Minimum 12 characters recommended
- Mix of uppercase, lowercase, numbers, and symbols
- Regular password rotation for admin accounts
Admin Key Management
Admin Key Management
- Store
KEY_FOR_ADMINin environment variables only - Rotate admin keys periodically
- Use different keys for development, staging, and production
- Never log or expose the admin key in responses
Email Verification
Email Verification
Consider implementing email verification for new registrations to:
- Confirm email ownership
- Prevent fake account creation
- Enable password recovery functionality
Next Steps
JWT Implementation
Learn how JWT tokens are generated and validated
Authentication Overview
Return to authentication system overview
