curl --request POST \
--url https://api.example.com/api/auth/login \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"user": {
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"role": {},
"status": {},
"avatar": "<string>",
"document_type": {},
"document_number": "<string>",
"refresh_token": {},
"created_at": "<string>",
"updated_at": "<string>"
},
"token": "<string>"
}Authenticate a user and receive a JWT access token
curl --request POST \
--url https://api.example.com/api/auth/login \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"user": {
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"role": {},
"status": {},
"avatar": "<string>",
"document_type": {},
"document_number": "<string>",
"refresh_token": {},
"created_at": "<string>",
"updated_at": "<string>"
},
"token": "<string>"
}z.string().email()z.string().min(1)Show User object properties
ADMIN, USERON, OFFDNI, PASSPORT, NIEJWT_SECRET environment variable{ userId, email, role }Bearer <token> for protected endpointsON (account is disabled).curl -X POST https://api.beils.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securePassword123"
}'
{
"user": {
"user_id": "550e8400-e29b-41d4-a716-446655440000",
"email": "[email protected]",
"name": "María",
"surname": "García",
"phone": "+34612345678",
"address": "Calle Mayor 123",
"city": "Madrid",
"country": "España",
"postal_code": "28013",
"gender": "female",
"birth_date": "1990-05-15T00:00:00.000Z",
"role": "USER",
"status": "ON",
"avatar": "https://example.com/avatars/user123.jpg",
"document_type": "DNI",
"document_number": "12345678A",
"refresh_token": null,
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-03-01T14:22:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1NTBlODQwMC1lMjliLTQxZDQtYTcxNi00NDY2NTU0NDAwMDAiLCJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLCJyb2xlIjoiVVNFUiIsImlhdCI6MTcwOTMwNDEyMCwiZXhwIjoxNzA5MzkwNTIwfQ.example_signature"
}
{
"statusCode": 401,
"statusMessage": "Correo o contraseña incorrectos"
}
{
"statusCode": 403,
"statusMessage": "Cuenta inactiva. Contacta con el administrador."
}
bcrypt.compare(). The original password is never returned in responses.
Source: server/api/auth/login.post.ts:46
signToken utility function from server/utils/jwt.ts:
const token = signToken({
userId: user.user_id,
email: user.email,
role: user.role
});
server/api/auth/login.post.ts:56
const loginSchema = z.object({
email: z.string().email(),
password: z.string().min(1),
});
server/api/auth/login.post.ts:7-10
/api/auth/me endpoint to retrieve current user information