feat: add admin role management with user authentication checks and update sidebar for admin access

This commit is contained in:
Julien Froidefond
2025-10-16 22:39:04 +02:00
parent 83f523c11a
commit 9899789fce
25 changed files with 1636 additions and 6 deletions

View File

@@ -15,3 +15,22 @@ export async function getCurrentUser(): Promise<UserData | null> {
authenticated: true,
};
}
export async function isAdmin(): Promise<boolean> {
const user = await getCurrentUser();
return user?.roles.includes("ROLE_ADMIN") ?? false;
}
export async function requireAdmin(): Promise<UserData> {
const user = await getCurrentUser();
if (!user) {
throw new Error("Unauthenticated");
}
if (!user.roles.includes("ROLE_ADMIN")) {
throw new Error("Forbidden: Admin access required");
}
return user;
}