Ui for admin. Logout successfull. Admin not reachable from homepage. Neither is logoutpage. Update for Architecture file.
This commit is contained in:
31
apps/public-web/app/(site)/admin/layout.tsx
Normal file
31
apps/public-web/app/(site)/admin/layout.tsx
Normal 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}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user