Quantcast
Viewing latest article 18
Browse Latest Browse All 39

Answer by zarpio for @nuxtjs/auth Why refresh page always redirect to login

Extending Fauzan Edris answer.

I was using Auth Nuxt, following fixed my issue.

export const actions = {  async nuxtServerInit({    commit  }, {    req  }) {    let auth = null    if (req.headers.cookie) {      // cookie found      try {        // check data user login with cookie        const {          data        } = await this.$axios.post('/user/profile')        // server return the data is cookie valid loggedIn is true        auth = data.data // set the data auth      } catch (err) {        // No valid cookie found        auth = null      }    }    // How we can set the user for AuthNuxt    // Source: https://auth.nuxtjs.org/api/auth    this.$auth.setUser(auth)  },}

Viewing latest article 18
Browse Latest Browse All 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>