Complete useAuth composable

This commit is contained in:
marzban-dev
2025-01-13 23:44:11 +03:30
parent ee641d76e9
commit 4dd0048ae2
+7 -8
View File
@@ -1,26 +1,25 @@
import { useCookies } from "@vueuse/integrations/useCookies";
import useGetAccount from "~/composables/api/account/useGetAccount";
export const useAuth = () => {
// state
const cookies = useCookies();
const token = ref("");
const token = useCookie("token");
// method
const updateToken = (newToken: string) => {
cookies.set("token", newToken);
token.value = newToken;
};
const logout = () => {
cookies.remove("token");
const logout = (reload ?: boolean) => {
token.value = undefined;
if (reload) window.location.reload();
};
// watch
watch(() => cookies.get("token"), (newValue) => {
watch(() => token.value, (newValue) => {
token.value = newValue;
}, {
immediate: true