Page reload messes up JWT in authorization header
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:
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!
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.
@conducto I think you are using LocalStorage helper from quasar. Try to use regular window.localStorage.
@ouaR Thank you! That totally solved it!
instead of using Quasar’s LocalStorage.set(‘token’, token) is just use window.localStorage.setItem(‘token’, token)
metalsadman last edited by metalsadman
If you are using the LocalStorage plugin, you need to use
$q.localStorage.getItem('token')function so the quasar prefix won’t be included. https://quasar.dev/quasar-plugins/web-storage#Usage
@metalsadman Great thanks! I should have RTFM and not only rely on the tutorial, I guess…