No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

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

    Persistence Auth with SSR

    Help
    2
    3
    602
    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.
    • ahiguita
      ahiguita last edited by

      Hi Guys,

      Maybe my question it’s very obvious, but I am having a problem to keep the auth in my SSR app.

      I am using Firebase Auth, I have set up the service for Server and Client, the problem is with the I am enabled the Auth because the storage and Cookies are cleaners.

      Does anyone know how I should handle this? Should I keep the Token on the client and then send it to Server? What do you advise me to solve this case with firebase Auth?

      1 Reply Last reply Reply Quote 0
      • T
        Tobias Mesquita last edited by Allan-EN-GB

        Regarding the firebase, i really don’t know, since them is completely out of of knowledge.

        But u can use the QCookies to share data between the client and server.

        https://quasar.dev/quasar-plugins/cookies#Note-about-SSR

        However, you aren’t able to read cookies from another domain, so you can’t read cookies of a third party api, like firebase.

        If u wanna to share a vuex module, you would use vuex-persistedstate, here a example.:

        import { Cookies } from 'quasar'
        import createPersistedState from 'vuex-persistedstate'
        
        export default function ({ store, ssrContext }) {
          const cookies = process.env.SERVER
            ? Cookies.parseSSR(ssrContext)
            : Cookies
        
          createPersistedState({
            paths: ['shared'],
            filter ({ type }) {
              return type.startsWith('shared')
            },
            storage: {
              getItem (key) {
                return JSON.stringify(cookies.get(key))
              },
              setItem (key, value) {
                cookies.set(key, value)
              },
              removeItem (key) {
                cookies.remove(key)
              }
            }
          })(store)
        }
        

        But remember, cookies are very limited, so be very selective about what you’ll persist.

        1 Reply Last reply Reply Quote 1
        • ahiguita
          ahiguita last edited by

          Hi @Tobias-Mesquita ,

          Thanks for reply.

          Yes, I was using the same structure… I had to find another solution, in this case, I am using the SW to have control of the firebase Auth in the Client-Side (https://firebase.google.com/docs/auth/web/service-worker-sessions?authuser=0) I can’t say that it was the most elegant solution because I still have some doubts about safety, but at least I could get unstuck in which he was.

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