CoastalCommitsPastes/client/app/admin/layout.tsx
2022-12-04 01:31:51 -08:00

17 lines
329 B
TypeScript

import { getCurrentUser } from "@lib/server/session"
import { redirect } from "next/navigation"
export default async function AdminLayout({
children
}: {
children: React.ReactNode
}) {
const user = await getCurrentUser()
const isAdmin = user?.role === "admin"
if (!isAdmin) {
return redirect("/")
}
return children
}