L
L
Lev Vorobyov2021-08-24 19:58:45
User identification
Lev Vorobyov, 2021-08-24 19:58:45

When loading Nuxt.js does not see the user?

I'm doing user authentication, but I ran into a problem. First, when loading , the middleware is loaded, it does not see the authorized user through $fire.auth.onAuthStateChanged . And if you go to another page, it sees the user. How can I make it see it on first boot?

middleware:

export default function ({app, route, redirect}) {
  console.log('middleware')
  app.$fire.auth.onAuthStateChanged(user => {
    if (user) {
      console.log('user+')
      if (route.path === perm.signin || route.path === perm.signup) {
        return redirect('/')
      }
    } else {
      console.log('user-')
      if (route.path !== perm.signin || route.path !== perm.signup) {
        return redirect(perm.signin)
      }
    }
  })
}


The picture shows console.log. It can be seen that the middleware was loaded first, then user- means that there is no user. But when you go to another page, it loads again, but with user+
612524f3b0ee0101036091.png

It is necessary that user+ be on the first run

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question