17 lines
488 B
TypeScript
17 lines
488 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import { CurrentUserDto } from '../types/user-response.interface';
|
|
import userHasPrivileges from '../utils/has-privileges';
|
|
|
|
export default function useHasPrivileges(
|
|
user: CurrentUserDto | undefined,
|
|
...privileges: (string | string[])[]
|
|
) {
|
|
const [hasPrivileges, setHasPrivileges] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setHasPrivileges(userHasPrivileges(user, ...privileges));
|
|
}, [user, privileges]);
|
|
|
|
return hasPrivileges;
|
|
}
|