title: TypeError: Cannot read property '0' of undefined passport-facebook
body: <p>Whenever I try to login using facebook, it will return this error, i have followed this link advise but still no luck. <a href="https://stackoverflow.com/questions/25832763/passport-facebook-dont-get-email">Passport-facebook doesn&#39;t get email</a></p>
  
  <pre><code>newUser.facebook.email = profile.emails[0].value;
                                             ^
  TypeError: Cannot read property '0' of undefined    
  </code></pre>
  
  <p>Here's the code</p>
  
  <pre><code>var passport = require('passport');
  var FacebookStrategy = require('passport-facebook').Strategy;
  var User = require('../models/user');
  
  var facebookConfig = {
    clientID: 'ID',
    clientSecret: 'SECRET',
    callbackURL: 'http://localhost:8080/facebook/callback'
  };
  
  var facebookInit = function(token, refreshToken, profile, callback) {
    User.findOne({ "facebook.id": profile.id }, function(err, user) {
      if (err) return callback(err);
  
      if (user) {
        return callback(null, user);
      }
  
      var newUser = new User();
      newUser.facebook.id = profile.id;
      newUser.facebook.token = token;
      newUser.facebook.email = profile.emails[0].value;
      newUser.facebook.displayName = profile.displayName;
      newUser.facebook.photo = profile.photos[0].value
  
      newUser.save(function(err) {
        if (err) {
          throw err;
        }
        return callback(null, newUser);
      });
    });
  }
  
  passport.use(new FacebookStrategy(facebookConfig, facebookInit));
  
  passport.serializeUser(function(user, callback) {
    callback(null, user.id)
  });
  
  passport.deserializeUser(function(id, callback) {
    User.findById(id, function(err, user) {
      callback(err, user);
    });
  });
  
  module.exports = {
    facebookLogin: passport.authenticate("facebook",  { scope: ['email'] }),
    facebookCallback: passport.authenticate("facebook", {
      successRedirect: "/profile",
      failureRedirect: "/"
    })
  }
  </code></pre>
  
  <p>I tried to change the scope from <code>{ scope: 'email' }</code> to <code>{ scope: ['email'] }</code>, still no luck.</p>