Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to add external service data to currently signed in user in Meteor

How to add external service data to currently signed in user in Meteor

Problem

I was playing with the loginWithExternalService methods under Accounts and I was sad to find that while you could create new users with one of these services or log in those who already had credentials, there was no way of allowing currently Logged in users to augment their methods of authentication so that they could log in with any of the services they have authenticated through. Is there a way of dumping information like a user's FB profile or a user's Twitter url into their existing, currently logged in account? I tried customizing accounts-base but this.userId returns null within it so I cannot do updates to the currently logged in user there.

Problem courtesy of: HGandhi

Solution

There should probably be a better API for this, but at the moment (Meteor 0.5.2) the following server code will create a user associated with an Facebook ID.

var newlyCreatedUserId = Accounts.updateOrCreateUserFromExternalService(
  'facebook',
  {id: FACEBOOK_ID},
  {additionalFieldOnUserDocumented: 'foo'}).id

If you dig into the implementation of Accounts.updateOrCreateUserFromExternalService you can see how to add these fields to an existing user.

Solution courtesy of: avital

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to add external service data to currently signed in user in Meteor

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×