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