User management in Meteor is so easy

I was pleasantly surprised how Meteor makes the developers life so easy. The official documentation for data security is available at http://docs.meteor.com/#dataandsecurity

When building web applications you might want to authorize users before using the application to the fullest extend. By default when you create the meteor application, any changes that happens at client and server will be seen by everyone else. By default, auto publish is enabled. When you go to production, you might not want everyone to see everyone’s changes. You want to authenticate and authorize users. This is standard task in any web applications. You end up coding once and then maintaining the code. Most of the time you create your own user tables and then perform email verification etc., As you can imagine, this is repeated task when developing new application and has clear pattern. Meteor framework team understood this pattern and provided you with easy to use solution. So in my code, with just 5 or 6 line of code, now I am able to provide login using,

  1. Creating user name and password.
  2. Creating user id with email and password.
  3. Twitter
  4. Facebook
  5. Google.

This makes developer life so easy. In the HTML all you have to add the new template provided by Meteor like the following

<div style="float: right; margin-right: 20px;"> {{> loginButtons}} </div>

Now this alone will not get you going, you need to add the meteor packages for making it work. So in the project terminal, add the following based on your requirement

By default you need to add following for option (1) and (2)

meteor add accounts-base
meteor add accounts-password
meteor add email
meteor add accounts-ui

Once you add all the above four packages, you will get Sign in option show up in the main page like the following

image

Now to make it work, you need to say, do you want to create users by just user id and password or email and password. This configuration need to happen in account ui configuration. You put the following code in client side javascript code

Accounts.ui.config({
   passwordSignupFields: 'USERNAME_AND_OPTIONAL_EMAIL'
});

Lets suppose you did add twitter/google/facebook by adding those packages in the console with following command

meteor add accounts-twitter
meteor add accounts-google
meteor add accounts-facebook

then your sign in screen will look like the following

image

Now, if you you want to authenticate using facebook or twitter, you need to register you all application with those identity providers before you can allow the users to authenticate.

But overall, with few lines of code, I got my user authentication completed and now I can focus on my actual application development.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s