javascript - How should I update user.profile on subsequent login (something similar to Accounts.onCreateUser)? -
i've been poking around in accounts packages, using modified version of ever-fabulous eventedmind customizing login screencast.
i modified use facebook instead of github, , noticed when trying update user.profile
information. specifically, i'm looking right way/place handle changes user.profile
.
let's say, example, authenticate fb user first time. when this, createuser
event fire. using accounts.oncreateuser(...)
, can populate additional information fb graph profile, so:
accounts.oncreateuser(function(options,user){ var accesstoken = user.services.facebook.accesstoken, result; result = meteor.http.get("https://graph.facebook.com/"+user.services.facebook.username, { params: { access_token:accesstoken, fields: ['picture', 'name','first_name','last_name','username','link','location','bio','relationship_status','email','timezone','locale'] } }); if (result.error){ throw result.error; } user.profile = result.data; //lazily adding return user; });
this works fine when user created. it's nice , clean.
but let's of information changes. example, let's profile picture changes. if log out , in meteor application, accounts.oncreateuser(...)
doesn't fire, because user exists. it's not being created again, it's being modified.
i need update user.profile
on subsequent logins, or @ least check changes , modify needed. i'd ideally in similar fashion .oncreateuser
. maybe .onmodifyuser
or something...
i can figure couple of ways using checking and/or client-side code, i'm wondering if there already-existing server hook cleaner.
any recommendations on cleanest way handle situation?
thanks in advance.
if you're manually calling login functions can pass callback last parameter called on client after login completes. see: http://docs.meteor.com/#meteor_loginwithpassword.
meteor.loginwithfacebook({}, function (err) { /* make meteor method call here */ });
there no documented server side callbacks @ moment.
Comments
Post a Comment