Files
peakskills/clients/domains/auth-client.ts
Julien Froidefond 42217c1c13 feat: enhance user authentication and profile retrieval
- Updated GET handler in auth route to fetch user UUID from cookie using AuthService.
- Improved error handling for unauthenticated and non-existent users.
- Added team name retrieval for the user profile, with fallback handling.
- Refactored AuthClient to return detailed user information including team details.
- Enhanced navigation component to use a dropdown menu for user actions, improving UI/UX.
- Implemented loading state in UserContext to manage user info fetching.
2025-08-25 16:33:10 +02:00

78 lines
1.6 KiB
TypeScript

import { BaseHttpClient } from "../base/http-client";
import { UserProfile } from "../../lib/types";
export interface LoginCredentials {
email: string;
password: string;
}
export interface RegisterData {
firstName: string;
lastName: string;
email: string;
password: string;
teamId: string;
}
export interface AuthUser {
id: string;
firstName: string;
lastName: string;
email: string;
teamId: string;
}
export class AuthClient extends BaseHttpClient {
/**
* Connecte un utilisateur avec email/password
*/
async login(
credentials: LoginCredentials
): Promise<{ user: AuthUser; message: string }> {
return await this.post("/auth/login", credentials);
}
/**
* Crée un nouveau compte utilisateur
*/
async register(
data: RegisterData
): Promise<{ user: AuthUser; message: string }> {
return await this.post("/auth/register", data);
}
/**
* Déconnecte l'utilisateur
*/
async logout(): Promise<{ message: string }> {
return await this.post("/auth/logout");
}
/**
* Récupère l'utilisateur actuel depuis le cookie
*/
async getCurrentUser(): Promise<{
firstName: string;
lastName: string;
teamId: string;
teamName: string;
uuid: string;
} | null> {
try {
const response = await this.get<{
user: {
firstName: string;
lastName: string;
teamId: string;
teamName: string;
uuid: string;
};
}>("/auth");
return response.user;
} catch (error) {
console.error("Failed to get current user:", error);
return null;
}
}
}