refactor: revew all design of services, clients, deadcode, ...
This commit is contained in:
33
clients/domains/auth-client.ts
Normal file
33
clients/domains/auth-client.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { BaseHttpClient } from "../base/http-client";
|
||||
import { UserProfile } from "../../lib/types";
|
||||
|
||||
export class AuthClient extends BaseHttpClient {
|
||||
/**
|
||||
* Authentifie un utilisateur et créé le cookie
|
||||
*/
|
||||
async login(
|
||||
profile: UserProfile
|
||||
): Promise<{ user: UserProfile & { uuid: string }; userUuid: string }> {
|
||||
return await this.post("/auth", profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère l'utilisateur actuel depuis le cookie
|
||||
*/
|
||||
async getCurrentUser(): Promise<UserProfile | null> {
|
||||
try {
|
||||
const response = await this.get<{ user: UserProfile }>("/auth");
|
||||
return response.user;
|
||||
} catch (error) {
|
||||
console.error("Failed to get current user:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Déconnecte l'utilisateur (supprime le cookie)
|
||||
*/
|
||||
async logout(): Promise<void> {
|
||||
await this.delete("/auth");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user