hermes-web/components/auth/role-gate.tsx

30 lines
508 B
TypeScript
Raw Normal View History

2024-01-04 03:56:24 -05:00
"use client"
import { UserRole } from "@prisma/client";
import { useSession } from "next-auth/react";
import React from "react";
interface RoleGateProps {
children: React.ReactNode
roles: UserRole[]
}
export const RoleGate = ({
children,
roles,
}: RoleGateProps) => {
const session = useSession()
const role = session?.data?.user.role as UserRole
if (roles.includes(role)) {
return (
<div>
{ children }
</div>
);
}
return <div />
}
export default RoleGate