Skip to main content

POST /api/auth/login

Authenticates a user with email and password credentials. On successful login, sets access and refresh tokens as HTTP-only cookies and updates the user’s last login timestamp.

Authentication

No authentication required.

Request Body

email
string
required
User’s email address.
password
string
required
User’s password.

Response

message
string
Success message confirming login.
user
object
The authenticated user object.
user.id
string
Unique user identifier.
user.email
string
User’s email address.
user.username
string
User’s username.
user.role
string
User’s role (“user” or “admin”).
user.wallet
string
User’s TRON wallet address.

Cookies Set

  • accessToken - JWT access token (HTTP-only, secure in production, 7 days expiry)
  • refreshToken - JWT refresh token (HTTP-only, secure in production, 7 days expiry)

Example Request

{
  "email": "[email protected]",
  "password": "SecurePass123"
}

Example Response

{
  "message": "Login successful",
  "user": {
    "id": "507f1f77bcf86cd799439011",
    "email": "[email protected]",
    "username": "johndoe",
    "role": "user",
    "wallet": "TRX7qS7n9qJCyXPZp3nYbH6KdQ3fPgDq8f"
  }
}

Error Responses

error
string
Error message describing what went wrong.

400 Bad Request

  • Email and password are required - One or both credentials are missing

401 Unauthorized

  • Invalid email or password - Credentials don’t match any user account
  • User account is inactive - The user account has been deactivated

500 Internal Server Error

  • Server error with error message details

Notes

  • Password is verified using bcrypt comparison (see ~/workspace/source/src/models/User.js:80)
  • The lastLogin field is updated with the current timestamp on successful login (see ~/workspace/source/src/api/auth/login.js:29)
  • Cookies use sameSite: 'strict' for CSRF protection
  • In production, cookies are set with the secure flag (HTTPS only)
  • Both access and refresh tokens have a 7-day expiry
  • Users must have isActive: true to login successfully

Build docs developers (and LLMs) love