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.
Overview
JSON Web Tokens (JWT) are the primary authentication mechanism for the Yucatan Public Works API. After successful login, you’ll receive a JWT token that must be included in all subsequent API requests.Obtaining a Token
To obtain a JWT token, send a POST request to the/auth/login endpoint with your credentials.
Endpoint
Request Body
User’s email address
User’s password
Example Request
Success Response
Error Response
If the credentials are invalid, you’ll receive a 401 Unauthorized response:Token Structure
JWT tokens consist of three parts separated by dots (.):Token Payload
The token payload contains the following claims:Subject - The user’s unique ID (UUID)
The user’s email address
The user’s role (e.g., “admin” or “user”)
Issued At - Timestamp when the token was created
Example Decoded Payload
The token payload is generated in
auth.service.ts:27-31 using the user’s information.Using Tokens in API Requests
Once you have a token, include it in theAuthorization header of your requests using the Bearer scheme.
Authorization Header Format
Example Requests
Token Validation
The API validates tokens using the Passport JWT strategy. The validation process:- Extracts the token from the Authorization header
- Verifies the signature using the secret key
- Checks expiration - expired tokens are rejected
- Decodes the payload and attaches user info to the request
jwt.strategy.ts:15-18
Token Expiration
The current implementation sets token expiration based on the JWT configuration. When a token expires:- The API will reject the token with a 401 Unauthorized response
- The client must request a new token by logging in again
jwt.strategy.ts:10
Currently, the API does not implement token refresh functionality. Users must log in again to obtain a new token after expiration.
Security Best Practices
Store tokens securely
Store tokens securely
- Never store tokens in localStorage (vulnerable to XSS attacks)
- Use httpOnly cookies or secure session storage
- Consider using memory storage for highly sensitive applications
Handle token expiration gracefully
Handle token expiration gracefully
- Implement automatic re-authentication when tokens expire
- Show user-friendly messages for expired sessions
- Consider implementing token refresh for better UX
Protect your tokens
Protect your tokens
- Never expose tokens in URLs or logs
- Use HTTPS in production to prevent token interception
- Implement token revocation for compromised accounts
Related Resources
Authentication Overview
Learn about the authentication system
Roles & Permissions
Understand role-based access control