export default defineNuxtRouteMiddleware(async () => {
  if (process.server) {
    return;
  }

  const route = useRoute();
  const { user, loading, refreshMe } = useAuth();

  if (loading.value) {
    await refreshMe();
  }

  if (!user.value) {
    return navigateTo(`/login?redirect=${encodeURIComponent(route.fullPath || "/")}`);
  }
});
