export default defineNuxtRouteMiddleware((to, from) => {
  // Skip on server side - let client handle auth
  if (process.server) {
    return;
  }

  // Skip middleware on login page
  if (to.path === '/login') {
    return;
  }

  const authStore = useAuthStore();

  // Restore session if not authenticated
  if (!authStore.isAuthenticated) {
    authStore.checkAuth();
  }

  // Check authentication after restore
  if (!authStore.isAuthenticated) {
    return navigateTo('/login');
  }
});