Skip to content

Auth API

XetaSuite utilise Laravel Sanctum en mode stateful (cookies) pour l’authentification SPA.

GET /sanctum/csrf-cookie

Réponse : Cookie XSRF-TOKEN défini


POST /api/v1/auth/login

Headers :

Content-Type: application/json
Accept: application/json
X-XSRF-TOKEN: {token from cookie}

Body :

{
"email": "user@example.com",
"password": "password",
"remember": true
}

Réponse 200 :

{
"two_factor": false
}

Réponse 422 (Validation) :

{
"message": "The provided credentials are incorrect.",
"errors": {
"email": ["The provided credentials are incorrect."]
}
}

Si two_factor: true dans la réponse login :

POST /api/v1/auth/two-factor-challenge

Body :

{
"code": "123456"
}

Ou avec un code de récupération :

{
"recovery_code": "abcd-efgh-ijkl"
}

POST /api/v1/auth/logout

Réponse 204 : No Content


GET /api/v1/user

Réponse :

{
"data": {
"id": 1,
"first_name": "Jean",
"last_name": "Dupont",
"full_name": "Jean Dupont",
"email": "jean@example.com",
"username": "jdupont",
"locale": "fr",
"current_site_id": 1,
"roles": ["admin"],
"permissions": ["company.viewAny", "company.view", "..."],
"sites": [
{
"id": 1,
"name": "Siège",
"is_headquarters": true
}
]
}
}

PATCH /api/v1/user/site

Body :

{
"site_id": 2
}

Réponse : Utilisateur mis à jour avec les nouvelles permissions pour le site sélectionné.


PATCH /api/v1/user/locale

Body :

{
"locale": "en"
}
httpClient.ts
const httpClient = axios.create({
baseURL: import.meta.env.VITE_API_URL || '',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
withCredentials: true, // Requis pour les cookies Sanctum
withXSRFToken: true, // Inclut automatiquement le header XSRF-TOKEN
});
// AuthRepository.ts
export const AuthRepository = {
login: async (credentials: LoginCredentials): Promise<void> => {
await httpClient.get('/sanctum/csrf-cookie');
await httpClient.post('/api/v1/auth/login', credentials);
},
logout: async (): Promise<void> => {
await httpClient.get('/sanctum/csrf-cookie');
await httpClient.post('/api/v1/auth/logout');
},
};