add HOC for role restriction

This commit is contained in:
memeriau
2022-04-12 23:51:16 +02:00
parent b67cb0afb1
commit 089af3880a
3 changed files with 15 additions and 2 deletions

View 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