Complete useAuth composable
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user