curl --request POST \
--url https://api.example.com/api/v1/auths/sign-in \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"username": "<string>",
"password": "<string>"
}
'{
"400": {},
"401": {},
"403": {},
"accessToken": "<string>",
"refreshToken": "<string>",
"user": {
"id": 123,
"username": "<string>",
"email": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"rol": "<string>",
"avatar": "<string>",
"status": "<string>",
"lastLogin": "<string>",
"createdAt": "<string>",
"permissions": [
{}
],
"stats": {}
}
}Authenticate a user and obtain access tokens
curl --request POST \
--url https://api.example.com/api/v1/auths/sign-in \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"username": "<string>",
"password": "<string>"
}
'{
"400": {},
"401": {},
"403": {},
"accessToken": "<string>",
"refreshToken": "<string>",
"user": {
"id": 123,
"username": "<string>",
"email": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"rol": "<string>",
"avatar": "<string>",
"status": "<string>",
"lastLogin": "<string>",
"createdAt": "<string>",
"permissions": [
{}
],
"stats": {}
}
}email or username along with password. At least one identifier (email or username) must be provided.email or username must be provided.email or username must be provided.Authorization header as a Bearer token for protected endpoints.Expiration: 24 hours from issuanceShow User Object Properties
interface LoginCredentials {
email?: string;
username?: string;
password: string;
}
interface LoginResponse {
accessToken: string;
refreshToken: string;
user: {
id: number;
email: string;
username: string;
firstName: string;
lastName: string;
rol: string;
avatar: string;
status: string;
lastLogin: string;
createdAt: string;
permissions: string[];
stats: Record<string, any>;
};
}
async function login(credentials: LoginCredentials): Promise<LoginResponse> {
const response = await fetch('https://api.example.com/api/v1/auths/sign-in', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(credentials),
});
if (!response.ok) {
throw new Error('Login failed');
}
const data = await response.json();
// Store tokens securely
localStorage.setItem('access_token', data.accessToken);
localStorage.setItem('refresh_token', data.refreshToken);
localStorage.setItem('user_data', JSON.stringify(data.user));
return data;
}
// Usage with email
const result = await login({
email: '[email protected]',
password: 'password123'
});
// Usage with username
const result = await login({
username: 'johndoe',
password: 'password123'
});
{
"statusCode": 401,
"message": "Invalid email or password"
}
{
"statusCode": 403,
"message": "Account is inactive. Contact administrator."
}
{
"statusCode": 400,
"message": "Validation failed",
"errors": [
"password must be at least 6 characters"
]
}
Authorization header for all authenticated requests:
Authorization: Bearer <accessToken>
accessToken and refreshTokenaccessToken in API requestsaccessToken expires, use refreshToken to get a new onerol field to role on the frontend. Make sure to handle this mapping in your client code.