0

I have a quasar app which communicates with an api. I am on the latest quasar version. For the datahandling I use vuex-orm.

Now when the app first is opened a user needs to login. I would then like to set a global object to the current loggedin user somewhere in the line of:

this.$user

I created a user.js in boot and registered it. This user object is available in all components and throughout the entire app. But during the boot process the user is not loggedin yet. In the Login.vue file, I log the user in and then set:

this.$user = res.response.data

When I set a breakpoint in the Login and call this.$user it shows the correct user. But when I switch to a different route for example the dashboard, then this.$user is empty again.

What am I doing wrong, or how can I set the this.$user variable so it stays persistant?

PWFraley
  • 1,052
  • 12
  • 20

1 Answers1

0

You should probably use a store with the a state management framework like Pinia with persistent state set to true rather than using a global user object.

See an example here: https://github.com/quasarframework/quasar/discussions/12539

Also, see this: https://github.com/prazdevs/pinia-plugin-persistedstate