POST /api/user/login
Authenticates a user with their email and password. Returns user information upon successful authentication.Headers
Must be
application/jsonRequest Body
User’s registered email address.
User’s password in plain text. Will be compared against the hashed password stored in the database.
Request Example
Response
200 - Login Successful
200 - Login Successful
Success message confirming user authentication.
User information object. Note: Password is excluded from the response for security.
User’s identification document number.
User’s email address.
User’s first name.
User’s last name.
User’s mobile phone number.
Type of user account.
Example Response
400 - Bad Request
400 - Bad Request
Returned when required fields are missing.
Error message describing the validation failure.
Missing Required Fields
401 - Unauthorized
401 - Unauthorized
500 - Internal Server Error
500 - Internal Server Error
Authentication Flow
- User submits email and password
- System validates that both fields are provided
- System looks up user by email in the database
- If user exists, password is compared using bcrypt
- If password matches, user information is returned (excluding password)
- If authentication fails at any step, appropriate error is returned
Security Notes
- Password is compared using bcrypt’s secure comparison
- Password hash is never returned in the response
- Invalid credentials return generic error message to prevent user enumeration
- Both missing user and invalid password return 401 status
Implementation Reference
The login endpoint is implemented in:- Route:
/home/daytona/workspace/source/src/routes/userRoutes.js:8 - Controller:
/home/daytona/workspace/source/src/controllers/userController.js:43