feat: secu migrate to user uuid
This commit is contained in:
@@ -11,7 +11,7 @@ export class AuthService {
|
||||
*/
|
||||
static async login(
|
||||
profile: UserProfile
|
||||
): Promise<{ user: UserProfile & { id: number }; userId: number }> {
|
||||
): Promise<{ user: UserProfile & { uuid: string }; userUuid: string }> {
|
||||
const response = await fetch("/api/auth", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -6,7 +6,21 @@ import { SkillsService } from "@/services/skills-service";
|
||||
import { SkillCategory, Team } from "./types";
|
||||
|
||||
/**
|
||||
* Récupère l'ID utilisateur depuis le cookie côté serveur
|
||||
* Récupère l'UUID utilisateur depuis le cookie côté serveur
|
||||
*/
|
||||
export async function getUserUuidFromCookie(): Promise<string | null> {
|
||||
const cookieStore = await cookies();
|
||||
const userUuidCookie = cookieStore.get("peakSkills_userId");
|
||||
|
||||
if (!userUuidCookie?.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return userUuidCookie.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère l'ID utilisateur depuis le cookie côté serveur (legacy)
|
||||
*/
|
||||
export async function getUserIdFromCookie(): Promise<number | null> {
|
||||
const cookieStore = await cookies();
|
||||
@@ -16,6 +30,7 @@ export async function getUserIdFromCookie(): Promise<number | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Essayer de parser comme number pour backward compatibility
|
||||
const userId = parseInt(userIdCookie.value);
|
||||
return isNaN(userId) ? null : userId;
|
||||
}
|
||||
@@ -24,17 +39,17 @@ export async function getUserIdFromCookie(): Promise<number | null> {
|
||||
* Récupère l'évaluation complète de l'utilisateur côté serveur
|
||||
*/
|
||||
export async function getServerUserEvaluation() {
|
||||
const userId = await getUserIdFromCookie();
|
||||
const userUuid = await getUserUuidFromCookie();
|
||||
|
||||
if (!userId) {
|
||||
if (!userUuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const evaluationService = new EvaluationService();
|
||||
|
||||
// Récupérer d'abord le profil utilisateur
|
||||
const userProfile = await evaluationService.getUserById(userId);
|
||||
// Récupérer d'abord le profil utilisateur via UUID
|
||||
const userProfile = await evaluationService.getUserByUuid(userUuid);
|
||||
|
||||
if (!userProfile) {
|
||||
return null;
|
||||
@@ -80,6 +95,6 @@ export async function getServerTeams(): Promise<Team[]> {
|
||||
* Vérifie simplement si l'utilisateur est authentifié via le cookie
|
||||
*/
|
||||
export async function isUserAuthenticated(): Promise<boolean> {
|
||||
const userId = await getUserIdFromCookie();
|
||||
return !!userId;
|
||||
const userUuid = await getUserUuidFromCookie();
|
||||
return !!userUuid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user