
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com>
14 lines
421 B
TypeScript
14 lines
421 B
TypeScript
import { useSession } from "next-auth/react";
|
|
import { FC, Fragment } from "react";
|
|
|
|
type AdminRequiredProps = {
|
|
as?: keyof JSX.IntrinsicElements;
|
|
};
|
|
|
|
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>;
|
|
};
|