juliomrqz / vue-warehouse

A Cross-browser storage for Vue.js and Nuxt.js, with plugins support and easy extensibility based on Store.js.
https://marquez.co/docs/vue-warehouse
MIT License
174 stars 9 forks source link

Unable to write cookie in nuxt asyncdata? #269

Open StringKe opened 4 years ago

StringKe commented 4 years ago

Is your feature request related to a problem? Please describe. Unable to write cookie in nuxt asyncdata

Describe the solution you'd like write cookie in nuxt asyncdata

Describe alternatives you've considered none

Additional context

asyncData({ $warehouse }: any): Promise<object | void> | object | void {
    const expiration = new Date().getTime() + 60 * 60 * 24 * 7
    $warehouse.set('token', 'asyncData', expiration)
},

image

welcome[bot] commented 4 years ago

Thanks for opening this issue, a maintainer will get back to you shortly! Be sure to follow the issue template! 🤓

StringKe commented 4 years ago

Other situations:

in custom axios

axios.js

export default function ({ $axios, redirect, $warehouse }) {
  $axios.onRequest((config) => {
    const token = $warehouse.get('token')
    if (token) {
      config.headers.Authorization = token
    }
    console.log('Making request to ' + config.url)
  })

  $axios.onError((error) => {
    const code = parseInt(error.response && error.response.status)
    if (code === 400) {
      redirect('/400')
    }
  })
}

server render error:

 ERROR  Cannot read property 'read' of undefined  

  at Object.get (node_modules/store/src/store-engine.js:22:27)
  at Object._checkExpiration (node_modules/store/plugins/expire.js:52:32)
  at Object.expire_get (node_modules/store/plugins/expire.js:25:21)
  at Object.pluginFn (node_modules/store/src/store-engine.js:140:25)
  at super_fn (node_modules/store/src/store-engine.js:133:19)
  at Object.get (node_modules/store/plugins/defaults.js:16:13)
  at Object.pluginFn [as get] (node_modules/store/src/store-engine.js:140:25)
  at server.js:61235:30
  at server.js:354:45