Meteor – Twitter/Facebook connexion

Posted by on Août 28, 2013 in Javascript, Meteor | No Comments

After my first article about Meteor and how to configure a simple user connexion, I wanted to show you how to use the Twitter/Facebook account connexion on your application.

First of all, you need to configure the Twitter/Facebook login button, It’s realy simple, you just have to follow the steps described by Meteor when you clic on the loggin button.

After that, you are able to use your Twitter/Facebook account for the connexion, but what you usualy wants is to retrieve all the Facebook/Twitter user informations to use them on your application.

Here’s how to do it (This code needs to be on the server side. ) :

The Accounts.onCreateUser is called whenever a user is created. Here whe just access to the Twitter/Facebook informations strored in the new user and use them.

Here’s what the new user object looks like :

Meteor twitter user object

Has you can see, all the information we need is already in user.service.twitter, the only thing I do is to get these informations and use them to create user.avatar and update the username. In fact you don’t realy need to do this, you can directly display the user.service.twitter/facebook informations, but in that case the username is going to be empty, and it is much more convenient to correctly initialise the user.

No need to  manualy  update the user in the collection, Meteor automaticaly do it after the Accounts.onCreateUser call.

It’s just realy as simple as it looks !