Nuxt Window Reload not picking up logged in user

Viewed 492

So we implemented a google signed in for our app. The signed in works, once the user is signed in, the authentication is done in the back end. The problem is that when the user logs in and is granted access to the pages in nuxt, if the user refreshes the window, it gets logged out.

This is my nuxt.config

auth: {
    strategies: {
      local: {
        endpoints: {
          login: {url: 'auth/login', method: 'post', propertyName: 'token'},
          user: { url: 'user', method: 'get', propertyName: 'data'},
          logout: { method: 'get', url: 'logout'}
        }
      }
    },
    redirect:{
      logout: '/signin'
    }
  },

  router: {
    middleware: ['auth']
  },

I am setting the user with nuxt auth library.

here is what I have:

export default {
    auth: false,
    data() {
      console.log('token',this.$route.query.token)
        return {
            token: this.$route.query.token ? this.$route.query.token : null
        }
    },
    mounted() {
        this.$auth.setUserToken('Bearer ' + this.token).then((res) => {
console.log(res.data.data)
            this.$auth.setUser(res.data.data);
            return this.$router.push('/');
        })
        .catch( (e) => {
            this.$auth.logout();
            return this.$router.push(`/auth/login?error=1`);
        });
    }
}

any ideas how I can keep the user logged in to true when the winder reloads?

1 Answers
Related