2022-04-26 08:48:17 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { FC } from "react";
|
|
|
|
import { Fragment } from "react";
|
2022-04-26 08:48:17 +00:00
|
|
|
|
|
|
|
type AdminRequiredProps = {
|
|
|
|
as?: keyof JSX.IntrinsicElements;
|
2022-05-17 19:31:49 +00:00
|
|
|
children?: React.ReactNode;
|
2022-04-26 08:48:17 +00:00
|
|
|
};
|
|
|
|
|
2022-09-08 15:35:31 +00:00
|
|
|
/** @deprecated use PermssionContainer instead. Will delete once V2 goes live */
|
2022-04-26 08:48:17 +00:00
|
|
|
export const AdminRequired: FC<AdminRequiredProps> = ({ children, as, ...rest }) => {
|
|
|
|
const session = useSession();
|
|
|
|
|
|
|
|
if (session.data?.user.role !== "ADMIN") return null;
|
|
|
|
const Component = as ?? Fragment;
|
|
|
|
return <Component {...rest}>{children}</Component>;
|
|
|
|
};
|