export default defineNuxtRouteMiddleware((to, from) => {
  const { username } = usePreferences()

  if (!username.value && to.name !== 'Login') {
    return navigateTo({ name: 'Login' })
  }

  if (!username.value)
    return

  const { init } = useMediasoup()

  init()

  if (to.path === 'Login') {
    return navigateTo('/')
  }
})
