Setting up Google Accounts

  • Start by creating a new meteor app (as you learned in AM6). Then, inside the folder of the app add the following packages:
  • meteor add accounts-google
    meteor add accounts-ui
  • Delete most of the code in the HTML page and simply add the Spacebars line: {{> loginButtons}}, which will show the interface elements for the login. At this poing the code in the HTML page can look somewhat like this:
      <h1>Google Accounts
      {{> loginButtons}}
  • Open the Meteor app on the browser, you should see something similar to this screenshot:
  • Clicking on the "Configure Google Login" button will display the following instructions. Follow them. You are familiar with going to the Google Console and getting a Client ID and secret, we have done this in AM1 (Google Books) and AM4 (Google Calendar).
  • If you followed the steps carefully, and clicked "Save Configuration", your HTML page would have changed to the following:
  • Now, clicking on the "Sign in with Google" will show the familiar window from AM4, about giving access to the Meteor app to lookup the user account information.
  • The result of the process is shown below. If desired, it is possible to configure the UI elements to display more (or different) information.

Doing more with the Google accounts

If we inspect what is saved in the MongoDB database, there will be a users collection which contains documents with multiple features for every user, for example, the whole name, their profile image, email address, etc.

Now that we are aware of what data about a user we're retrieving and storing for a user logging in with their Google account, we can think of ways of displaying (or somehow using) that information.

There are different ways in which we can refer to the logged-in user.

  1. In the HTML code, using the Spacebars syntax, {{currentUser}}.
  2. In the JS code, by invoking the Meteor.user() method.

Invoking the method in the console, shows that this method does the same as the method db.users.findOne() that was shown above in the Mongo console (server side). Now that we know how to access the information about the current user, we can write JS code to access the nested fields (through the dot notation), and use Meteor method helpers to assign the values to Spacebars variables. The following example demonstrates this technique.

{{#if currentUser}}
  <p><img src="{{profileURL}}" width=30> 
        Hello, {{firstName}}!</p>
   firstName: function(){
    var user = Meteor.user(); 
    if (user) {
   profileURL: function() {
    var user = Meteor.user(); 
    if (user) {

Referring to all users

Given that packages such as accounts-google (or accounts-password) create by default the collection users in MongoDB, we can refer to it directly in our code as Meteor.users. If we have autopublish on, we can write code on the client side to perform certain operations ,e.g., showing the photos and names of all users who have used the app.

<template name="allUsers">
<div id="allUsers">
  <h4>All app users</h4>
  {{#each users}}
    <li><img src="{{photoURL}}" width=50> <span>{{username}}</span></li>
    users: function(){
      return Meteor.users.find({}, {"": 1, 
                             "": 1,
                             "" : 1});
    username: function(){
    photoURL: function(){

Adding the above code to the one we originally had, will make our app look like below:


When you deploy the app on, you will have to go through the same process of configuring Google Login. Simply go to the Google console and add information with the web URL of your app, for example, this is the app in these notes:


You can find the live instance on:

The code is in this GitHub repo: