Authentication
Manage customer authentication, registration, profile, and account operations.Register Customer
POST /api/ecom/auth/register
Register a new customer account
Request Body
Customer email address (max 60 characters)
Password (minimum 8 characters, max 60)
Customer RUC or CED number (10-13 characters)
Optional customer details
Response
Success message: “Usuario registrado exitosamente”
Example Request
Example Response
The password is hashed using bcrypt before storage. Passwords must be at least 8 characters long.
Login
POST /api/ecom/auth/login
Authenticate customer and receive JWT token
Request Body
Customer email address (can also use
user field)Customer password
The API accepts both
email and user fields for backward compatibility. Either field can be used for the email address.Response
JWT authentication token
Example Request
Example Response
Error Responses
Error message for invalid credentials
401 Unauthorized
400 Bad Request
Check Client Availability
GET /api/ecom/auth/client/:cli_ruc_ced
Check if a client RUC/CED is available for registration
Path Parameters
Customer RUC or CED number (10-13 characters)
Response Scenarios
Status message indicating availability
Example Request
Example Responses
200 OK - Available
409 Conflict - Already Registered
404 Not Found - Must Register
Get Profile (Protected)
GET /api/ecom/auth/me
Get authenticated customer profile
Headers
Bearer token from login responseFormat:
Bearer {token}Response
Customer profile data from database
Example Request
Example Response
Update Password (Protected)
PUT /api/ecom/auth/password
Update customer password
Headers
Bearer token from login response
Request Body
New password (minimum 8 characters)
Response
Success message
Example Request
Example Response
The new password is hashed before updating in the database. After updating, the customer must login again with the new password.
Delete Account (Protected)
DELETE /api/ecom/auth/
Delete customer account
Headers
Bearer token from login response
Response
Success message
Example Request
Example Response
Authentication Flow
The typical authentication flow for e-commerce customers:- Check Client Availability: Use
GET /api/ecom/auth/client/:cli_ruc_cedto check if RUC/CED is available - Register: Create account with
POST /api/ecom/auth/register - Login: Authenticate with
POST /api/ecom/auth/loginto receive JWT token - Use Token: Include token in
Authorization: Bearer {token}header for protected endpoints - Access Protected Resources: Use cart, payment, and profile endpoints with the token
JWT tokens expire based on the
JWT_EXPIRES_IN environment variable. When a token expires, the customer must login again to receive a new token.Error Handling
All authentication endpoints follow standard HTTP status codes:200 OK: Request successful201 Created: Resource created successfully400 Bad Request: Invalid input data401 Unauthorized: Invalid credentials or missing/invalid token404 Not Found: Resource not found409 Conflict: Resource already exists500 Internal Server Error: Server error
Source Code Reference
Implementation details can be found in:- Routes:
/src/routes/ecom.auth.routes.js - Controller:
/src/controllers/ecom.auth.controller.js - DTOs:
/src/dtos/auth.dto.js - Model:
/src/models/auth.model.js