I handled authentication with cookies in Nuxt, the code is as bellow:
nuxtServerInit ({ commit, state }, { req }) {
console.log('nuxtServerInit')
if (req.headers.cookie) {
let cookieParsed = cookieparser.parse(req.headers.cookie)
// console.log(cookieParsed)
if (cookieParsed.token !== undefined && cookieParsed.userId !== undefined) {
// console.log('parsed.token', cookieParsed)
let token = null
token = cookieParsed.token
state.userId = cookieParsed.userId
commit('auth/setToken', token)
}
}
},
But, while I test and I login I could access succesfully to my account. But if I try in another Pc or in a new incognito window in Chrome I could access to the same account that I did before. How is it possible? It seems cookies are stored globally. But in the code I get cookies from req (the client request). Please let me know what I missed out.
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c6825">#c6825</a>)</em></sub></div>