Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to write cookie in nuxt asyncdata? #269

Open
StringKe opened this issue Jul 2, 2020 · 2 comments
Open

Unable to write cookie in nuxt asyncdata? #269

StringKe opened this issue Jul 2, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@StringKe
Copy link

StringKe commented Jul 2, 2020

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
Copy link

welcome bot commented Jul 2, 2020

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

@StringKe
Copy link
Author

StringKe commented Jul 2, 2020

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

@juliomrqz juliomrqz self-assigned this Jul 31, 2020
@juliomrqz juliomrqz added the bug Something isn't working label Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants