add client/admin pages, show info and created admin api and server actions
This commit is contained in:
23
components/auth/role-gate.tsx
Normal file
23
components/auth/role-gate.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
'use client'
|
||||
|
||||
import { UserRole } from '@prisma/client'
|
||||
import { useCurrentRole } from '@/hooks/useCurrentRole'
|
||||
import FormError from '@/components/form-error'
|
||||
|
||||
interface RoleGateProps {
|
||||
children: React.ReactNode
|
||||
allowedRole: UserRole
|
||||
}
|
||||
|
||||
export const RoleGate = ({
|
||||
children,
|
||||
allowedRole,
|
||||
}: RoleGateProps) => {
|
||||
const role = useCurrentRole()
|
||||
|
||||
if (role !== allowedRole) {
|
||||
return <FormError message="You do not have permission to view this content!"/>
|
||||
}
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
Reference in New Issue
Block a user