2026-01-21 18:13:35 +01:00
|
|
|
import { NextResponse } from 'next/server';
|
|
|
|
|
import { getCurrentUser } from '@/lib/auth';
|
2026-01-22 18:53:23 +01:00
|
|
|
import { prisma } from '@/lib/prisma';
|
2026-01-21 18:13:35 +01:00
|
|
|
|
|
|
|
|
// GET - Récupérer l'utilisateur actuel
|
|
|
|
|
export async function GET() {
|
|
|
|
|
try {
|
|
|
|
|
const user = await getCurrentUser();
|
|
|
|
|
if (!user) {
|
|
|
|
|
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
|
|
|
|
|
}
|
2026-01-22 18:53:23 +01:00
|
|
|
|
|
|
|
|
// Récupérer l'utilisateur avec son rôle
|
|
|
|
|
const userWithRole = await prisma.user.findUnique({
|
|
|
|
|
where: { id: user.id },
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
email: true,
|
|
|
|
|
name: true,
|
2026-02-08 14:21:07 +01:00
|
|
|
photoUrl: true,
|
2026-01-22 18:53:23 +01:00
|
|
|
roleId: true,
|
|
|
|
|
role: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
description: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return NextResponse.json(userWithRole);
|
2026-01-21 18:13:35 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors de la récupération de l\'utilisateur:', error);
|
|
|
|
|
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|