CoastalCommitsPastes/client/app/admin/layout.tsx

18 lines
329 B
TypeScript
Raw Normal View History

2022-12-04 04:31:51 -05:00
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
}