fix: login was KO by profile
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { UserProfile } from "@/lib/types";
|
||||
import { userService } from "@/services/user-service";
|
||||
|
||||
// Constantes pour les cookies (définies ici car auth-service.ts a été supprimé)
|
||||
export const COOKIE_NAME = "peakSkills_userId";
|
||||
export const COOKIE_MAX_AGE = 30 * 24 * 60 * 60; // 30 jours
|
||||
@@ -29,4 +32,52 @@ export class AuthService {
|
||||
const userUuid = await this.getUserUuidFromCookie();
|
||||
return !!userUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentifie un utilisateur et retourne la configuration du cookie
|
||||
*/
|
||||
static async authenticateUser(profile: UserProfile): Promise<{
|
||||
userUuid: string;
|
||||
cookieConfig: {
|
||||
name: string;
|
||||
value: string;
|
||||
options: {
|
||||
maxAge: number;
|
||||
httpOnly: boolean;
|
||||
secure: boolean;
|
||||
sameSite: "lax" | "strict" | "none";
|
||||
path: string;
|
||||
};
|
||||
};
|
||||
}> {
|
||||
// Vérifier si l'utilisateur existe déjà avec ces informations
|
||||
const existingUser = await userService.findUserByProfile(profile);
|
||||
let userUuid: string;
|
||||
|
||||
if (existingUser) {
|
||||
// Mettre à jour l'utilisateur existant si nécessaire
|
||||
if (existingUser.teamId !== profile.teamId) {
|
||||
await userService.updateUserByUuid(existingUser.uuid, profile);
|
||||
}
|
||||
userUuid = existingUser.uuid;
|
||||
} else {
|
||||
// Créer un nouvel utilisateur
|
||||
userUuid = await userService.upsertUserUuid(profile);
|
||||
}
|
||||
|
||||
return {
|
||||
userUuid,
|
||||
cookieConfig: {
|
||||
name: COOKIE_NAME,
|
||||
value: userUuid,
|
||||
options: {
|
||||
maxAge: COOKIE_MAX_AGE,
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user