From 4dd0048ae23ecd8c207e80264f4fa587324fea07 Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Mon, 13 Jan 2025 23:44:11 +0330 Subject: [PATCH] Complete useAuth composable --- frontend/composables/useAuth.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/composables/useAuth.ts b/frontend/composables/useAuth.ts index 84310d8..831ad40 100644 --- a/frontend/composables/useAuth.ts +++ b/frontend/composables/useAuth.ts @@ -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