Refactor page components to use NavigationWrapper and integrate Prisma for data fetching. Update EventsSection and LeaderboardSection to accept props for events and leaderboard data, enhancing performance and user experience. Implement user authentication in ProfilePage and AdminPage, ensuring secure access to user data.

This commit is contained in:
Julien Froidefond
2025-12-09 14:11:47 +01:00
parent b1f36f6210
commit 67131f6470
14 changed files with 1041 additions and 944 deletions

View File

@@ -0,0 +1,42 @@
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import Navigation from "./Navigation";
interface UserData {
username: string;
avatar: string | null;
hp: number;
maxHp: number;
xp: number;
maxXp: number;
level: number;
}
export default async function NavigationWrapper() {
const session = await auth();
let userData: UserData | null = null;
const isAdmin = session?.user?.role === "ADMIN";
if (session?.user?.id) {
const user = await prisma.user.findUnique({
where: { id: session.user.id },
select: {
username: true,
avatar: true,
hp: true,
maxHp: true,
xp: true,
maxXp: true,
level: true,
},
});
if (user) {
userData = user;
}
}
return <Navigation initialUserData={userData} initialIsAdmin={isAdmin} />;
}