Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refetch user in Vuex with Nuxt Auth Module?

Tags:

nuxt.js

vuex

Short Question: Is it possible to update the user data in Vuex manually via the Nuxt Auth Module?

Why do I have that Question: My problem is this. I save some Likes/Follows in MongoDB in the user document. My authentication is realized with Nuxt Auth. Nuxt Auth stores my user document in Vuex on login.

If an user likes something now, it will be stored in the database, but I don't get it into the auth state of Nuxt Auth in Vuex.

An alternative (I thought) would be to change the data in Vuex the same way as in the database. But here I get problems with the "Strict" mode of Vuex.

One possibility that works for me would be to save the user data one more time in a separate state and always update it manually. But do I really have to save the user data several times in Vuex? Doesn't make sense to me.

like image 763
Jakob Kühne Avatar asked Oct 26 '25 20:10

Jakob Kühne


1 Answers

Now I found a solution. It is as simple as:

this.$auth.fetchUser()

but I couldn't find it anywhere in the documentation.

Source: https://nuxt-auth.herokuapp.com/

like image 195
Jakob Kühne Avatar answered Oct 29 '25 16:10

Jakob Kühne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!