refactor: update authentication flow and cookie management
- Changed COOKIE_NAME from "peakSkills_userId" to "session_token" for better clarity. - Updated AuthClient to handle login and registration with new data structures. - Enhanced AuthWrapper to manage user sessions and display appropriate messages. - Added error handling in LoginForm and RegisterForm for better user feedback. - Refactored user service methods to streamline user creation and verification processes.
This commit is contained in:
@@ -1,14 +1,51 @@
|
||||
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 {
|
||||
/**
|
||||
* Authentifie un utilisateur et créé le cookie
|
||||
* Connecte un utilisateur avec email/password
|
||||
*/
|
||||
async login(
|
||||
profile: UserProfile
|
||||
): Promise<{ user: UserProfile & { uuid: string }; userUuid: string }> {
|
||||
return await this.post("/auth", profile);
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,11 +60,4 @@ export class AuthClient extends BaseHttpClient {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Déconnecte l'utilisateur (supprime le cookie)
|
||||
*/
|
||||
async logout(): Promise<void> {
|
||||
await this.delete("/auth");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user