Reputation: 1712
I have a project that is utilizing the Meteor accounts package. I have a user signed in with no username field. When I try and update it while it is running on the localhost, using Meteor.users.update({}, {$set:{username:"Zach Ary"}})
it works beautifully, and the change is reflective via the accounts-ui, and meteor mongo
. However, when I deploy it to the remote meteor server, and try to update it, no change is shown. Any ideas?
This is the code used on the server (for testing purposes only)
Meteor.users.allow({
update:function(userId, upd) {
console.log(upd)
return true;
}
})
Thanks
Upvotes: 0
Views: 1045
Reputation: 1712
Ok, so this caught me off guard. Apparently this has nothing to do with publishing it to the server, rather it was just a misleading coincidence. The problem stems from my update command Meteor.users.update({}, {$set:{username:"Zach Ary"}})
. For this to work, it needs to be Meteor.users.update({_id:Meteor.userId()}, {$set:{username:"Zach Ary"}})
. Otherwise it tries to update the user that was previously logged in. I don't know if this is a bug, or a misunderstood feature, but it seems to do the trick.
Upvotes: 0
Reputation: 2420
Not sure this is your issue, but on the development server Meteor autopublishes all of your collections.
When you bundle and deploy, you need to manually publish your collections.
Something like this on the server:
Meteor.publish("userData", function () {
return Meteor.users.find({_id: this.userId});
});
and on the client
Meteor.subscribe("userData")
Upvotes: 1