
var mongo = require('./mongo');

var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;

var uuid = require('uuid');


passport.use(new FacebookStrategy({

    clientID: process.env.FB_APP_ID,
    clientSecret: process.env.FB_APP_SECRET,
    callbackURL: 'http://' + process.env.SERVICE_HOSTNAME + '/auth/facebook/callback',
    enableProof: false

}, function (accessToken, refreshToken, profile, done) {

    mongo.Account.findOneAndUpdate({

        facebookId: profile.id

    }, {

        displayName: profile.displayName,
        givenName: profile.name.givenName,
        familyName: profile.name.familyName,
        givenName: profile.name.givenName

    }, {

        upsert: true

    }).exec().then(function (account) {

        if (!account.id) {

            account.id = uuid.v4();

        }

        if (!account.createdAt) {

            account.createdAt = new Date();

        }

        return account.psave().then(function () {

            done(null, account);

        });

    }, function (err) {

        done(err);

    });

}));

module.exports = passport;

@@ -923,16 +923,26 @@
 w Date()
+.getTime()
 ;%0A%0A     
@@ -1086,24 +1086,119 @@
 done(err);%0A%0A
+    %7D).then(null, function (err) %7B%0A%0A        console.log(err);%0A        console.log(err.stack);%0A%0A
     %7D);%0A%0A%7D))

Fix type of createAt