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

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

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

  if (!user.value) {
    return navigateTo("/login");
  }

  if (user.value.role !== "admin") {
    return navigateTo("/");
  }
});
