Added basic user roles
This commit is contained in:
30
components/auth/role-gate.tsx
Normal file
30
components/auth/role-gate.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
"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
|
||||
Reference in New Issue
Block a user