meteor - Add extra user field -


in meteor app use default accounts package, gives me default login , registration functionality. want add field user, nickname, , logged in user possibility edit information.

for editing profile suppose should doing this:

template.profileedit.events({   'submit form': function(e) {     e.preventdefault();      if(!meteor.user())       throw new meteor.error(401, "you need login first");      var currentuserid = this._id;      var user = {       "profile.nickname": $(e.target).find('[name=nickname]').val()     };      meteor.users.update(currentuserid, {       $set: user     }, function(error){       if(error){         alert(error.reason);       } else {         router.go('myprofile', {_id: currentuserid});       }     });    } }); 

but doesn't store info if in mongo. when showing profile, {{profile.nickname}} returns empty. wrong here?

edit: added collections\users.js show permissions:

meteor.users.allow({   update: function (userid, doc) {     if (userid && doc._id === userid) {       return true;     }   } });  meteor.users.deny({   update: function(userid, user, fieldnames) {     return (_.without(fieldnames, 'profile.nickname').length > 0);   } }); 

yeah, believe should job, although haven't run code. idea right.

the main things aware of are:

  1. the necessity allow user doc edited client appropriate meteor.users.allow() block on server, assuming you're going remove "insecure" package (which need before doing in production).
  2. the fact "by default server publishes username, emails, , profile", you'll need write meteor.publish function on server , subscribe if want expose other fields within user document client once you've removed "autopublish" package (which again, should).

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -