Documentation Index
Fetch the complete documentation index at: https://mintlify.com/LizandroCanul/back_sdo/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
The Yucatan Public Works API uses JWT (JSON Web Token) based authentication to secure endpoints and control access to resources. This authentication system ensures that only authorized users can access the API and that different user roles have appropriate permissions.How Authentication Works
The API implements a token-based authentication flow:- User Login: Client sends credentials (email and password) to the
/auth/loginendpoint - Credential Validation: Server validates credentials using bcrypt password comparison
- Token Generation: If valid, server generates a JWT token containing user information
- Token Usage: Client includes the token in subsequent API requests
- Token Verification: Server validates the token on each protected endpoint request
- Access Control: Server checks user roles to determine if access is allowed
Authentication Flow
Security Features
The authentication system implements several security best practices:Password Hashing with bcrypt
All passwords are hashed using bcrypt before being stored in the database. This ensures that even if the database is compromised, passwords remain secure.auth.service.ts:18
JWT Token Security
JWT tokens are signed with a secret key and include:- Expiration checking: Tokens expire after a configured time period
- Signature verification: Ensures tokens haven’t been tampered with
- Payload encryption: User data is encoded in the token
jwt.strategy.ts:9
Role-Based Access Control
The API uses role-based access control (RBAC) to restrict access to certain endpoints based on user roles. This is enforced through:- JwtAuthGuard: Validates the JWT token
- RolesGuard: Checks if the user has the required role
- @Roles() Decorator: Specifies which roles can access an endpoint
Protected Endpoints
Most endpoints in the API require authentication. The authentication guards are applied at the controller level:obras.controller.ts:23
Next Steps
JWT Tokens
Learn how to obtain and use JWT tokens
Roles & Permissions
Understand role-based access control