mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-07-04 09:20:53 +00:00
31 lines
612 B
TypeScript
31 lines
612 B
TypeScript
import prisma from "@/lib/prisma";
|
|
import { auth, signIn } from "@/lib/auth";
|
|
import { redirect } from "next/navigation";
|
|
|
|
interface AdminProtectedLayoutProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export const AdminProtectedLayout = async ({
|
|
children,
|
|
}: AdminProtectedLayoutProps) => {
|
|
const session = await auth();
|
|
const userId = session?.user?.id;
|
|
if (!userId) {
|
|
await signIn();
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
select: {
|
|
role: true,
|
|
},
|
|
where: {
|
|
id: userId,
|
|
},
|
|
});
|
|
|
|
if (user?.role !== "ADMIN") redirect("/unauthorized");
|
|
|
|
return <>{children}</>;
|
|
};
|