Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive auth user #314

Closed
Hiws opened this issue Oct 22, 2019 · 3 comments
Closed

Reactive auth user #314

Hiws opened this issue Oct 22, 2019 · 3 comments

Comments

@Hiws
Copy link

Hiws commented Oct 22, 2019

So I've tried to follow the docs and 2.0 PR #216

Got everything working pretty well. I can login and send messages back and forth.
(Followed this guide for the flow https://docs.feathersjs.com/guides/basics/setup.html)

I made a profile page to update the logged in users information.

The flow i used for that is

const { User } = this.$FeathersVuex.api;
let user = User.getFromStore(authUser._id);
if (!user) {
  user = await User.get(authUser._id);
}
this.user = user.clone();

I then edit the copy and call this.user.save() once I'm done to commit the changes and update the server.

This does not appear to update authenticated user in the store state.auth.user.

To fix this i added the following to my makeAuthPlugin which takes the user information returned from the server upon login and creates a User model using that information and now the auth.user automatically updates since i now clone the model from auth and save that instead.

actions: {
  responseHandler({ commit, state }, response) {
    const apiService = "api";
    if (state.userService) {
      let user = response[state.responseEntityField];
      const Model = Object.keys(models[apiService])
        .map(modelName => models[apiService][modelName])
        .find(model => model.servicePath === state.userService);
      if (Model) {
        user = new Model({ ...response.user });
        commit("setUser", user);
      }
    }
  }
}

Am i doing something wrong, since i would expect the auth.user to be reactive by default, or was that changed in the 2.0 pre-release? And if that is the case, is the above approach the correct one to solve the issue?

I'm using feathers: 4.3.7 on the server and client and feathers-vuex: 2.0.0-pre78

@marshallswain
Copy link
Member

@Hiws could you try using feathers-vuex@2.0.1 (non-pre). I released it yesterday.

@marshallswain
Copy link
Member

The code you have posted is almost exactly identical to what's in the final released version.

@Hiws
Copy link
Author

Hiws commented Oct 22, 2019

@marshallswain

It works perfectly after upgrading!
Thanks you for all the great work, thoroughly impressed with what you've made.

@Hiws Hiws closed this as completed Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants