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

  const { isAuthenticated, memberData, checkMemberStatus } = useAuth()

  if (!isAuthenticated.value) {
    await checkMemberStatus()
  }

  if (!isAuthenticated.value) {
    return navigateTo('/')
  }

  if (memberData.value?.role !== 'admin') {
    return navigateTo('/members')
  }
})
