I am using vue-cookie package which lets me to set and get cookies with ease. What I want is to get this cookie in nuxtServerInit():
async nuxtServerInit() {
const res = await this.$axios.post('/me', {}, {
headers: {
'Authorization': 'Bearer ' + $nuxt.$cookie.get('token')
}
})
}
But, I always get $nuxt is not defined error. Please help!
vue cookie is a wrapper around tiny-cookie . Tiny cookie is for browser. So it wont work on server e.g. in nuxtServerInit
In nuxtServerInit you should get cookies from req.cookies
async nuxtServerInit(_, { req }) {
console.log(req.headers.cookie)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With