Skip to main content
The auth endpoints handle user registration and authentication. These are the only public endpoints that don’t require an access token.

Sign up

POST /api/auth/signup Create a new user account and receive an access token.

Request body

email
string
required
User’s email address (must be valid format)
name
string
required
User’s full name
password
string
required
User’s password (min 6 characters recommended)
phone
string
User’s phone number (optional)
role
string
User’s role (optional, defaults to ‘user’)

Response

message
string
Success message: “You have signed up successfully!”
data
object
user
object
id
string
Unique user identifier (UUID)
email
string
User’s email address
name
string
User’s full name
phone
string
User’s phone number
status
string
User status (active/inactive)
createdAt
string
Account creation timestamp
updatedAt
string
Last update timestamp
token
string
JWT access token for authentication

Example request

curl -X POST https://your-domain.com/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "name": "Jane Smith",
    "password": "securePass123",
    "phone": "+1234567890"
  }'
const response = await fetch('https://your-domain.com/api/auth/signup', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: '[email protected]',
    name: 'Jane Smith',
    password: 'securePass123',
    phone: '+1234567890'
  })
});

const data = await response.json();
console.log(data.data.token);

Example response

{
  "message": "You have signed up successfully!",
  "data": {
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "[email protected]",
      "name": "Jane Smith",
      "phone": "+1234567890",
      "status": "active",
      "createdAt": "2024-03-04T10:00:00.000Z",
      "updatedAt": "2024-03-04T10:00:00.000Z"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjU1MGU4NDAwLWUyOWItNDFkNC1hNzE2LTQ0NjY1NTQ0MDAwMCIsImVtYWlsIjoiYXJ0aXN0QGV4YW1wbGUuY29tIiwiaWF0IjoxNzA5NTUzNjAwfQ.xyz"
  }
}

Error responses

400 Bad Request - Invalid email format
{
  "statusCode": 400,
  "message": "Invalid email address"
}
409 Conflict - User already exists
{
  "message": "User already exists",
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "email": "[email protected]"
  }
}

Login

POST /api/auth/login Authenticate with existing credentials and receive an access token.

Request body

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

Response

message
string
Success message: “You have logged in successfully!”
data
object
user
object
User object (same structure as signup)
token
string
JWT access token for authentication

Example request

curl -X POST https://your-domain.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "securePass123"
  }'
const response = await fetch('https://your-domain.com/api/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: '[email protected]',
    password: 'securePass123'
  })
});

const data = await response.json();
localStorage.setItem('token', data.data.token);

Example response

{
  "message": "You have logged in successfully!",
  "data": {
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "[email protected]",
      "name": "Jane Smith",
      "phone": "+1234567890",
      "status": "active",
      "createdAt": "2024-03-04T10:00:00.000Z",
      "updatedAt": "2024-03-04T10:00:00.000Z"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Error responses

401 Unauthorized - Invalid credentials
{
  "statusCode": 401,
  "message": "Invalid credentials"
}

Build docs developers (and LLMs) love