import { skipHydrate } from "pinia";
import { useStorage } from "@vueuse/core";

export const useAuthStore = defineStore("auth", () => {
  const token = useStorage("token", null);

  const hasToken = computed(() => Boolean(token.value));

  const setToken = (val) => {
    token.value = val;
  };

  const cleanToken = () => {
    token.value = null;
  };

  // watch(token, (val) => {
  //   console.log("token", val);
  // });

  return {
    token: skipHydrate(token),
    hasToken,
    setToken,
    cleanToken,
  };
});
