export default defineNuxtRouteMiddleware(async () => {
  const { activeLogtoOrgId, setActiveTeam } = useActiveTeam()
  const me = useState<{
    activeTeamId?: string | null
    activeTeam?: { logtoOrgId?: string | null } | null
  } | null>('me', () => null)

  // Already loaded - skip
  if (activeLogtoOrgId.value) return
  if (!me.value?.activeTeamId || !me.value.activeTeam?.logtoOrgId) return

  setActiveTeam(me.value.activeTeamId, me.value.activeTeam.logtoOrgId)
})
