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
User’s email address (must be valid format)
User’s password (min 6 characters recommended)
User’s phone number (optional)
User’s role (optional, defaults to ‘user’)
Response
Success message: “You have signed up successfully!”
Unique user identifier (UUID)
User status (active/inactive)
Account creation timestamp
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
Response
Success message: “You have logged in successfully!”
User object (same structure as signup)
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"
}