This repository has been archived on 2024-06-14. You can view files and clone it, but cannot push or open issues or pull requests.
icynet-admin/lib/hooks/useHasPrivileges.ts
2022-08-29 21:09:28 +03:00

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;
}