feat: add server-side role guard to manage layout (moderator+)

This commit is contained in:
2026-05-16 17:13:03 +08:00
parent 4ec97a92ab
commit e089fb2cf7
+11
View File
@@ -1,5 +1,8 @@
import { ManageSidebar } from "@/components/manage/manage-sidebar"
import { auth } from "@/lib/auth"
import type { Metadata } from "next"
import { headers } from "next/headers"
import { redirect } from "next/navigation"
export const metadata: Metadata = {
title: {
@@ -14,6 +17,14 @@ export default async function ManageLayout({
}: {
children: React.ReactNode
}) {
const session = await auth.api.getSession({
headers: await headers(),
})
const role = session?.user?.role ?? "user"
if (role !== "moderator" && role !== "admin") {
redirect("/")
}
return (
<section className='w-full flex flex-col gap-8 py-16'>
<div className='px-4 md:px-8 lg:px-12'>