Feathers-vuex: Reactive auth user

Created on 22 Oct 2019  路  3Comments  路  Source: feathersjs-ecosystem/feathers-vuex

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

Most helpful comment

@marshallswain

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

All 3 comments

@Hiws could you try using [email protected] (non-pre). I released it yesterday.

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

@marshallswain

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juancampuzano picture juancampuzano  路  4Comments

RubyRubenstahl picture RubyRubenstahl  路  5Comments

Heartnett picture Heartnett  路  4Comments

rayfoss picture rayfoss  路  7Comments

ontoneio picture ontoneio  路  7Comments