Meteor onCreateUser issue -
i using meteor , people can connect site via facebook. i'm using people username identify them. but, of them don't have username. example, new user has null username. i'm trying is, if person has username ok use username. if not, wanna use facebook id username. problem is, if condition not working properly. if person has username, if condition considers person doesn't. weird thing is, if console.log of username before if condition, show username. once in if, considers username null. here code :
accounts.oncreateuser(function(options, user) { var fb = user.services.facebook; var token = user.services.facebook.accesstoken; if (options.profile) { options.profile.fb_id = fb.id; options.profile.gender = fb.gender; options.profile.username = fb.username console.log( 'username : ' + options.profile.username); if ( !(options.profile.username === null || options.profile.username ==="null" || options.profile.username === undefined || options.profile.username === "undefined")) { console.log('noooooooo'); options.profile.username = fb.id; } else { console.log('yessssssss'); options.profile.username = fb.username; } options.profile.email = fb.email; options.profile.firstname = fb.first_name; user.profile = options.profile; } sendwelcomeemail(options.profile.name, options.profile.email); return user; }); with code, if log in facebook has username. condition show 'noooooooo' console.log( 'username : ' + options.profile.username); show username. why that? :l
it's because creating called before logging , logging asynchronous .. cannot ensure if or not true/false. putting information fb service redundant, because these informations saved user.
http://docs.meteor.com/#meteor_user
you should obtain information user after loggedin because in moment able recognise kind of identifier can use username/id.
//server side meteor.publish("userdata", function () { return meteor.users.find({_id: this.userid}); // can publish facebook id.. /*return meteor.users.find({_id: this.userid}, { fields: { 'services.facebook.id': true } } );*/ }); //client side meteor.subscribe("userdata"); // .. can see more informations logged user console.log(meteor.users.find({}).fetch());
Comments
Post a Comment