Availability based on permissions
This commit is contained in:
17
frontend/hooks/use-roles.tsx
Normal file
17
frontend/hooks/use-roles.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import getMe from "@/lib/getMe";
|
||||
import { Role } from "@/types/types";
|
||||
import { getCookie } from "cookies-next";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useRoles() {
|
||||
const [roles, setRoles] = useState<Role[] | null>(null);
|
||||
const cookie = getCookie("auth_token");
|
||||
useEffect(() => {
|
||||
if (cookie)
|
||||
getMe(cookie?.toString()).then((me) => {
|
||||
setRoles(me?.data?.roles ?? null);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return roles;
|
||||
}
|
||||
Reference in New Issue
Block a user