refactor: auth service for logic in evaluation skill PUT

This commit is contained in:
Julien Froidefond
2025-08-25 10:50:39 +02:00
parent d575596c71
commit ee58eb82e5
2 changed files with 28 additions and 21 deletions

View File

@@ -33,6 +33,32 @@ export class AuthService {
return !!userUuid;
}
/**
* Vérifie l'authentification et retourne le profil utilisateur
* @throws {Error} avec status 401 si non authentifié ou 404 si utilisateur non trouvé
*/
static async requireAuthenticatedUser(): Promise<{
userUuid: string;
userProfile: UserProfile;
}> {
const userUuid = await this.getUserUuidFromCookie();
if (!userUuid) {
const error = new Error("Utilisateur non authentifié");
(error as any).status = 401;
throw error;
}
const userProfile = await userService.getUserByUuid(userUuid);
if (!userProfile) {
const error = new Error("Utilisateur introuvable");
(error as any).status = 404;
throw error;
}
return { userUuid, userProfile };
}
/**
* Authentifie un utilisateur et retourne la configuration du cookie
*/