export default defineNuxtRouteMiddleware((to, from) => {
  if (import.meta.server) return;

  const authStore = useAuthStore();
  const { token } = storeToRefs(authStore);

  if (token.value) return;

  if (to.fullPath.includes("/profile")) {
    return navigateTo("/login", {
      replace: true,
      query: {
        redirect: to.fullPath,
      },
    });
  }

  if (to.fullPath.includes("/note-create")) {
    return navigateTo("/login", {
      replace: true,
      query: {
        redirect: to.fullPath,
      },
    });
  }
  return;
});
