vue.jsnuxt.jsvuexnuxt-auth

How to keep users logged in after browser close with nuxt auth?


I have the following inside my nuxt.config.js file:

auth: {
  strategies: {
    local: {
      scheme: 'local',
      token: {
        property: 'meta.token',
        global: true,
      },
      user: {
        property: 'data',
      },
      endpoints: {
        login: { url: '/auth/login', method: 'post' },
        logout: { url: '/auth/logout', method: 'post' },
        user: { url: '/auth/user', method: 'get' }
      }
    },
  }
},

After a short (but still unknown amount of time for me), user is logged out. Also, after closing and opening the browser, user is always logged out. How could I persist the logged in state even after closing the browser? Also, why could be the reason for users be logged out after a short amount of time?

Inspecting cookies I have in my bearer token:

Expires / Max-Age:"Session"

And I have in my local storage:

auth._token_expiration.local:"1656703495434"

Solution

  • Using this.$auth.$storage.setUniversal('user', response.data, true) was enough to solve OP's issue.

    As shown here: https://auth.nuxtjs.org/api/storage/#universal-storage