Ui for admin. Logout successfull. Admin not reachable from homepage. Neither is logoutpage. Update for Architecture file.

This commit is contained in:
Domonkos
2026-01-28 16:52:47 +01:00
parent 086e5a867d
commit a094a35a8b
9 changed files with 1384 additions and 156 deletions

View File

@@ -0,0 +1,31 @@
import { redirect } from "next/navigation";
import { headers } from "next/headers";
async function cookieHeader() {
const h = await headers(); // ✅ await
return h.get("cookie") ?? "";
}
export default async function AdminLayout({
children,
}: {
children: React.ReactNode;
}) {
const res = await fetch(`${process.env.BACKEND_URL}/api/me`, {
headers: { cookie: await cookieHeader() }, // ✅ await here too
cache: "no-store",
});
if (res.status === 401) redirect("/login");
if (!res.ok) redirect("/login");
const me = await res.json();
const isAdmin =
Array.isArray(me?.authorities) &&
me.authorities.some((a: any) => a.authority === "ROLE_ADMIN");
if (!isAdmin) redirect("/");
return <>{children}</>;
}