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.
This commit is contained in:
46
app/api/auth/profile/route.ts
Normal file
46
app/api/auth/profile/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { AuthService, userService } from "@/services";
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
// Vérifier si l'utilisateur est connecté
|
||||
const userUuid = await AuthService.getUserUuidFromCookie();
|
||||
|
||||
if (!userUuid) {
|
||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||
}
|
||||
|
||||
// Récupérer les données de mise à jour
|
||||
const { firstName, lastName, teamId } = await request.json();
|
||||
|
||||
// Validation des données
|
||||
if (!firstName || !lastName || !teamId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Tous les champs sont requis" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Mettre à jour l'utilisateur
|
||||
await userService.updateUserByUuid(userUuid, {
|
||||
firstName,
|
||||
lastName,
|
||||
teamId,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Profil mis à jour avec succès",
|
||||
user: {
|
||||
firstName,
|
||||
lastName,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("Profile update error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Erreur lors de la mise à jour du profil" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user