diff --git a/frontend/composables/useAuth.ts b/frontend/composables/useAuth.ts new file mode 100644 index 0000000..84310d8 --- /dev/null +++ b/frontend/composables/useAuth.ts @@ -0,0 +1,31 @@ +import { useCookies } from "@vueuse/integrations/useCookies"; + +export const useAuth = () => { + + // state + + const cookies = useCookies(); + + const token = ref(""); + + // method + + const updateToken = (newToken: string) => { + cookies.set("token", newToken); + }; + + const logout = () => { + cookies.remove("token"); + }; + + // watch + + watch(() => cookies.get("token"), (newValue) => { + token.value = newValue; + }, { + immediate: true + }); + + return { token, updateToken, logout }; + +}; \ No newline at end of file