Navigation

    Quasar Framework

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Need help with ssr

    Framework
    2
    2
    17
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dbehterev last edited by

      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.

      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @dbehterev last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post