Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
921 stars 166 forks source link

Race condition when creating new user with multiple role and subscribing to same data #264

Closed tejaser closed 6 years ago

tejaser commented 6 years ago

I am using below metoer method to create new user: Meteor.methods({ "users.add": function(newUser) { let cResult = Accounts.createUser({ username: newUser.username, email: newUser.email, password: newUser.password, profile: { first_name: newUser.first_name, last_name: newUser.last_name, clinic: newUser.clinic } }); for (let index in newUser.roles) { Roles.addUsersToRoles(cResult, newUser.roles[index].label); } return true; }, "users.addRole": function(userId, newRole) { Roles.addUsersToRoles(userId, newRole); return true; } });

However, getting race condition in the default rendering, if i refersh I am getting the correct data. My github repo is https://github.com/tejaser/clinic.git

tejaser commented 6 years ago

Finally resolved by putting a simple check on the react render method for undefined which allowed it render new data with null and then update it when the information came from the roles subscribe method.