mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 13:56:29 +02:00
add HOC for role restriction
This commit is contained in:
12
src/utils/withUserRole.tsx
Normal file
12
src/utils/withUserRole.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import React from "react"
|
||||
import { useSelector } from "react-redux"
|
||||
import { selectUserRoles } from "../store/auth"
|
||||
|
||||
function withUserRole<T>(requiredRole: string, Component: React.ComponentType<T>) {
|
||||
return (props: T): JSX.Element | null => {
|
||||
const roles = useSelector(selectUserRoles)
|
||||
return roles.includes(requiredRole) ? <Component {...props} /> : null
|
||||
}
|
||||
}
|
||||
|
||||
export default withUserRole
|
Reference in New Issue
Block a user