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

    Page reload messes up JWT in authorization header

    Help
    6
    8
    1031
    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.
    • C
      conducto last edited by

      Hello!

      I have implemented JWT authentication with Quasar 1.0.4 using Axios and Vuex following this tutorial: https://pusher.com/tutorials/authentication-vue-vuex

      When I have logged into my application successfully I receive a JWT from my backend and store it in Vuex as well as in LocalStorage. But if I do a complete page reload in the browser, the authentication header gets messed up:
      Bildschirmfoto 2019-08-19 um 23.32.09.png
      In front of the token the string “__q_strn” is prefixed. When I googled for this I only could find a error reporting with an accepted PR on Github from 2017 ( https://github.com/quasarframework/quasar/issues/1199 ) stating that this was fixed.

      Did somebody of you experience this kind of behaviour? It seems that Quasar has trouble updating the value in LocalStorage after the page reload.

      Thanks for your help!
      C.

      1 Reply Last reply Reply Quote 0
      • patryckx
        patryckx last edited by

        @conducto There is something in this tutorial that I do not agree with. Modifying localStorage values ​​through the action. I usually use mutation for these changes.

        1 Reply Last reply Reply Quote 0
        • O
          ouaR last edited by

          @conducto I think you are using LocalStorage helper from quasar. Try to use regular window.localStorage.

          C 1 Reply Last reply Reply Quote 0
          • C
            conducto @ouaR last edited by conducto

            @ouaR Thank you! That totally solved it!

            Details:
            instead of using Quasar’s LocalStorage.set(‘token’, token) is just use window.localStorage.setItem(‘token’, token)

            1 Reply Last reply Reply Quote 0
            • metalsadman
              metalsadman last edited by metalsadman

              If you are using the LocalStorage plugin, you need to use getItem ie. $q.localStorage.getItem('token') function so the quasar prefix won’t be included. https://quasar.dev/quasar-plugins/web-storage#Usage

              C 1 Reply Last reply Reply Quote 0
              • C
                conducto @metalsadman last edited by

                @metalsadman Great thanks! I should have RTFM and not only rely on the tutorial, I guess…

                1 Reply Last reply Reply Quote 0
                • waelio
                  waelio last edited by

                  So that means that storing values using $q.localStorage with winder them inaccessible for others using window.localstorage.getItem ?

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

                    @waelio It doesn’t make them inaccessible to other code using native local storage, but Quasar uses a custom serialization method to preserve objects that you would have to deal with. I’m sure you can find the code responsible for that in the Quasar codebase, or just don’t use the $q.localStorage helper.

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