rubystarashe / nuxt-vuex-localstorage

MIT License
161 stars 18 forks source link

How do I sync this with my server? #14

Closed adivity closed 3 years ago

adivity commented 5 years ago

Currently I have:

isTokenSet(state) { if (state.token) { return true; } else { return false}

But, on the server, it lists the token as false, which is causing rendering errors. How do I sync this with the server?

drewbaker commented 4 years ago

Yeah I'd like my server to also have access to the persisted store on server-side render (from nuxtServerInit for example).

adivity commented 4 years ago

I can't remember this exactly, but I think it was caused by the wrong Authentication. I was trying to save the token returned from the API to the browser's local storage as well as to Vuex Store. The same way I do it for regular VueJS.

The solution for Nuxt: I needed to use the following module: https://auth.nuxtjs.org/

rubystarashe commented 3 years ago

If you access to persisted store by browser storage with server side methods, It logically means that client side rendering must be performed before the server method can be executed.

To make this possible, it means that encrypted data from the browser storage must be passed to the nuxt server before the nuxt page is rendered, and there is no way to handle it at the nuxt module level.

So if you really need it, you have to make the server page plugins for it. Server side router -> serve not rendered page for take browser storage data to server side -> make persisted store with the data -> render nuxt page with the storage