Endpoint
Request
User’s email address
User’s password (plain text, will be compared against bcrypt hash)
Request Format
The endpoint expects form data (application/x-www-form-urlencoded or multipart/form-data).
Response
JWT token for authenticated requests (user ID)
Authentication status:
true on successAlways
null on successful authenticationExample Request
Example Responses
Successful Login (200)
Successful Login (200)
Bearer: HTTP-only cookie containing JWT token (24h expiration)user: Cookie containing user ID (24h expiration)
Authentication Failed (401)
Authentication Failed (401)
- Invalid email (user not found)
- Incorrect password
- Account not active (
status != "active") - Database connection issues
Authentication Flow
1. User Lookup
The system retrieves the user from MongoDB usingGetUserByEmail():
2. Status Verification
User status must be “active”:active: Can log inpending: Registration incomplete- Other statuses: Access denied
3. Password Verification
Password is compared against bcrypt hash:4. Token Generation
On success, the user’s ID is returned as the token:Session Management
The login endpoint sets cookies for session management:Bearer Cookie (HTTP-only)
- Name:
Bearer - Value: JWT token
- Expires: 24 hours from login
- Path:
/ - HttpOnly:
true(prevents XSS access)
User Cookie
- Name:
user - Value: User ID
- Expires: 24 hours from login
- Path:
/ - HttpOnly:
false
Source Code References
- Handler:
backend/auth/routes.go:13-HandleUserLogin - Logic:
backend/auth/controller.go:13-processUserLogin - Model:
backend/users/model.go:47-GetUserByEmail
Error Handling
All errors return HTTP status 401 with error details:- User Not Found:
GetUserByEmailreturns MongoDB “not found” error - Inactive Account: “user is not active”
- Invalid Password: “the password provided is not valid”
Security Considerations
- Passwords are verified using
bcrypt.CompareHashAndPassword - HTTP-only cookies prevent XSS attacks on tokens
- Only “active” users can authenticate
- No timing attacks: bcrypt comparison is constant-time
- Token expires after 24 hours
Related Endpoints
- POST /register - Create new user account
- JWT Tokens - JWT token structure and validation