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

17 lines
488 B
TypeScript
Raw Normal View History

2022-08-29 18:09:28 +00:00
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;
}