Skip to content

Instantly share code, notes, and snippets.

@guiomie guiomie/gist:1396895
Created Nov 27, 2011

Embed
What would you like to do?
everyauth
var express= require('express');
var Promise = everyauth.Promise;
everyauth.helpExpress(app);
everyauth.facebook
.appId(fbId)
.appSecret(fbSecret)
.logoutPath('/logout')
.logoutRedirectPath('/')
.handleAuthCallbackError( function (req, res) {
//Define here for routing in case user decline app
})
.findOrCreateUser( function (session, accessToken, accessTokExtra, fbUserMetadata) {
//Verifies if user in database already
try{
var id = fbUserMetadata.id;
var promise = this.Promise();
User.findOne({ fbid: id}, function(err, result) {
var user;
if(!result) {
//iniate also the users unique reference doc in ref collection
var newUserRefDoc = new GeneralReference();
//newUserWorkoutRef = emptyWorkoutRef;
user = new User();
user.fbid = id;
newUserRefDoc.id = id;
user.firstName = fbUserMetadata.first_name;
user.lastName = fbUserMetadata.last_name;
user.save();
newUserRefDoc.save();
} else {
user = result;
}
//console.log(user);
promise.fulfill(user);
});
return promise;
}
catch(err){
console.log(err);
}
})
.redirectPath('/view/profile');
app.configure(function(){
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({secret: cookieSecret}));
app.use(everyauth.middleware());
app.use(express.favicon());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.