POST /api/v1/auth/refresh
Exchanges a valid refresh token for a new access token and refresh token pair. This endpoint implements token rotation for enhanced security.Request Body
The JWT refresh token received from the login or previous refresh requestThe token will be revoked and replaced with a new one as part of the rotation process.
Response
Indicates if the request was successful
Error Responses
401 Unauthorized
Invalid, expired, or revoked refresh token
403 Forbidden
User account has been deactivated since the token was issued
404 Not Found
User associated with the token no longer exists
Token Rotation
This endpoint implements automatic token rotation for enhanced security:-
When you send a valid refresh token, the system:
- Validates and decodes the token
- Revokes the old refresh token (marked with reason:
rotation) - Creates a new refresh token with a fresh expiration time
- Generates a new access token
- Returns both new tokens
-
The operation is atomic - both revocation and creation happen in a database transaction:
- If the database fails midway, the transaction rolls back
- The original token remains valid and you can retry
- This prevents token loss during network failures
-
The new refresh token inherits device information from the old one:
deviceId- Device UUIDdeviceName- Human-readable device nameuserAgent- Updated if provided in request contextipAddress- Updated if provided in request context
Token Payload
The new access token contains:sub- User ID (UUID)role- User role (ADMIN,VENTANA, orVENDEDOR)ventanaId- Associated ventana ID (null for ADMIN users)bancaId- Associated banca ID (derived from ventana, null for ADMIN users)iat- Issued at timestampexp- Expiration timestamp
Best Practices
- Store tokens securely - Never expose tokens in URLs or logs
- Handle 401 errors - When you receive a 401, prompt the user to log in again
- Refresh proactively - Refresh tokens before the access token expires (e.g., when you receive a 401 on a protected endpoint)
- Don’t retry infinitely - If refresh fails with 401, redirect to login
- Update storage - Always replace both tokens after a successful refresh