Need help with ssr
-
Hello there. Have lack of information about proper using SSR. Only some common things from official docs. Could anybody give me some advice how to use SSR (or work code) especially in VUEX.
First question, is how to use cookies in Vuex actions.
For example, this code is not working (in Vuex action).import { LocalStorage, Cookies } from 'quasar' import { cookie } from 'boot/axios' import { i18n } from 'boot/i18n' export function configAction ({ commit, ssrContext }, locale) { ... const cookies = process.env.SERVER ? Cookies.parseSSR(ssrContext) : Cookies // otherwise we're on client cookie ? cookies.set('locale', locale, { expires: 365 }) : LocalStorage.set('locale', locale, { expires: 365 }) ...
I got error “cookies.set is not a function”. As I understood, you couldn’t use Cookies either LocalStorage. But how use it in SSR context?
Or similar question, how to use cookie in Vuex state? Smth. like that:import { Cookies, LocalStorage } from 'quasar' import { cookie } from 'boot/axios' export default function (data) { console.log(data) const cookies = process.env.SERVER ? Cookies.parseSSR(ssrContext) : Cookies // otherwise we're on client return { user: null, users: [], token: cookie ? cookies.get('token') : LocalStorage.getItem('token'), cookie } }
If anybody could give me any hints I’ll be grateful. Thanks.
-
@dbehterev This is a great article: https://dev.to/quasar/quasar-ssr-using-cookies-with-other-libs-services-4nkl
It’s a lot to understand, but it does go over the pitfalls of cookies and SSR and how to avoid them.