0

I am trying to use Nuxt/auth, but run into problem with session saving in localStorage.

Login.vue

methods: {
sendLoginLink() {
  this.$auth.loginWith('local', {
    data: {
      username: "test@gmail.com",
      password: "testpassword"
    }
  }).then((date) => {
    console.log("data", date)
  }).catch((err) => {
    console.error("err", err)
  })
}

Nuxt.config.js

 auth: {
strategies: {
  local: {
    endpoints: {
      login: { url: '/dashboard', method: 'post', propertyName: 'token' }
    },
    tokenType: ''
  }
}

axios: {
baseURL: 'http://localhost:1234'
},

  modules: [
'@nuxtjs/axios',
'@nuxtjs/auth-next', 
]

When the user logs in, the function sendLoginLink is called and throw error in console:

enter image description here

Which means that the auth-token is so large that it cannot be stored in localStorage, but all other things related to this function are saved in localStorage. For example:

enter image description here

I googled a lot but didn't find a good solution to the problem. For example, I tried to clear all localStorage memory before running sendLoginLink() function but the result is the same. Different browsers have the same problem

Sergei Eensalu
  • 377
  • 1
  • 15
  • 1
    PS: cookies tend to be more secure than `localStorage`. Meanwhile, the max limit for cookie is 4KB, while this is 5MB for `localStorage`. IMO, the issue here is more of **why** you do have the size limit reached? Are you sure the backend is sending you the correct thing (a small simple string is enough for the token). Maybe try to inspect your storage before and after to see how it may reach the allowed max: https://stackoverflow.com/a/15720835/8816585 – kissu Aug 03 '21 at 08:49

0 Answers0