2023-09-08 11:28:50 +03:00
|
|
|
import { redirect } from 'next/navigation';
|
|
|
|
|
|
|
|
|
|
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-session';
|
2023-09-08 12:56:44 +03:00
|
|
|
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
2023-09-08 11:28:50 +03:00
|
|
|
|
|
|
|
|
export type AdminLayoutProps = {
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default async function AdminLayout({ children }: AdminLayoutProps) {
|
|
|
|
|
const user = await getRequiredServerComponentSession();
|
|
|
|
|
const isUserAdmin = isAdmin(user);
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
redirect('/signin');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isUserAdmin) {
|
|
|
|
|
redirect('/dashboard');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <main className="mt-8 pb-8 md:mt-12 md:pb-12">{children}</main>;
|
|
|
|
|
}
|