refactor: auth service for logic in evaluation skill PUT
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user