Skip to main content

Login

Authenticate a user with email and password to receive a JWT access token.

Endpoint

POST /auth/login

Request

email
string
required
User’s email address. Must be a valid email format.
password
string
required
User’s password. Must be at least 8 characters.

Response

success
boolean
Indicates whether the request was successful
message
string
Success message indicating the user logged in successfully
data
object
Response data containing user information and authentication token

Example Request

curl -X POST https://api.example.com/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "password123"
  }'

Example Response

{
  "success": true,
  "message": "User logged in successfully",
  "data": {
    "user": {
      "id": 1,
      "role": "USER",
      "name": "John Doe",
      "email": "[email protected]",
      "phone": "+1234567890"
    },
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
    "expires_in": 3600
  }
}

Error Responses

{
  "success": false,
  "message": "We can't find a user with that email address.",
  "errors": {
    "email": "We can't find a user with that email address."
  }
}
{
  "success": false,
  "message": "These credentials do not match our records.",
  "errors": {
    "password": "These credentials do not match our records."
  }
}
{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "email": [
      "The email must be a valid email address."
    ]
  }
}
{
  "success": false,
  "message": "The given data was invalid.",
  "errors": {
    "password": [
      "The password must be at least 8 characters."
    ]
  }
}

Build docs developers (and LLMs) love