nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.53k stars 4.99k forks source link

Help wanted about cookies-js #681

Closed StudiowebPro closed 7 years ago

StudiowebPro commented 7 years ago

in my store i have next code:

import Cookies from 'cookies-js'

const state = {
  user: null,
  token: Cookies('token') ? Cookies('token') : null
}
export default {
  state,
  mutations
}

end i can see next error:

Nuxt.js Error:

Error: Cookies.js requires a `window` with a `document` object
    at factory (D:\prj\nuxt\node_modules\cookies-js\dist\cookies.js:12:19)
    at Object.module.exports.Object.defineProperty.value (store/user.js:9:17)
    at __webpack_require__ (webpack:/webpack/bootstrap dfe6cf738e49c9418da8:25:0)
    at webpackContext (webpack:/store ^\.\/.*\.js$:6:0)
    at getModule (.nuxt/store.js:9:13)
    at Object.module.exports.Object.defineProperty.value (.nuxt/store.js:50:19)
    at __webpack_require__ (webpack:/webpack/bootstrap dfe6cf738e49c9418da8:25:0)
    at Object.<anonymous> (server-bundle.js:805:68)
    at __webpack_require__ (webpack:/webpack/bootstrap dfe6cf738e49c9418da8:25:0)
    at Object.<anonymous> (server-bundle.js:1908:65)
    at __webpack_require__ (webpack:/webpack/bootstrap dfe6cf738e49c9418da8:25:0)
    at server-bundle.js:95:18
    at Object.<anonymous> (server-bundle.js:98:10)
    at evaluateModule (D:\prj\nuxt\node_modules\vue-server-renderer\build.js:6967:21)
    at D:\prj\nuxt\node_modules\vue-server-renderer\build.js:6985:15
    at D:\prj\nuxt\node_modules\vue-server-renderer\build.js:6983:12

but i see examples with this code snd it work... what i can do for work with cookies-js?

This question is available on Nuxt.js community (#c591)
pi0 commented 7 years ago

@StudiowebPro Handeling cookies in server side is different from client side. (See simple implementation here)

StudiowebPro commented 7 years ago

@pi0 in this issue #429 a person writes that this code works ...

StudiowebPro commented 7 years ago

@pi0 Thank's, i decide problem with set abd load token, your code help me.

pi0 commented 7 years ago

You can use https://github.com/nuxt/nuxt-modules/blob/master/modules/auth/store.js instead :)

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.