20 lines
542 B
TypeScript
20 lines
542 B
TypeScript
import { useMemo } from 'react'
|
|
|
|
import { PermissionKeysType } from '@type/roles.type.ts'
|
|
|
|
import { useAppSelector } from './redux.ts'
|
|
|
|
export const useRole = () => {
|
|
const { profile } = useAppSelector((state: any) => state.profileReducer)
|
|
const role: string = useMemo(() => profile && profile.role, [profile])
|
|
|
|
const hasPermission = (permission: PermissionKeysType) => {
|
|
const userPermission = profile.permissions || []
|
|
return userPermission.includes(permission)
|
|
}
|
|
|
|
return { role, hasPermission }
|
|
}
|
|
|
|
export default useRole
|