Created
August 24, 2011 00:46
-
-
Save guiomie/1167029 to your computer and use it in GitHub Desktop.
Saving new user, put it always saves the same thing in mongodb (first authenticated user) I'm using everyauth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.findOrCreateFacebookUser = function(fbUserData, promise){ | |
User.findOne({_id:fbUserData.id}, function(err, user) { | |
if(err) { | |
console.log("Error in finding user for auth. Check Db"); | |
promise.fail(err); | |
return; | |
} | |
else if(user){ | |
console.log("User found "); | |
promise.fulfill(user); | |
} | |
else{ | |
var joiningUser = new User(); | |
joiningUser._id = fbUserData.id; | |
joiningUser.firstName = fbUserData.first_name; | |
joiningUser.lastName = fbUserData.last_name; | |
joiningUser.email = fbUserData.email; | |
//console.log(JSON.stringify(joiningUser)); | |
joiningUser.save(function(err){ | |
if(err){ | |
console.log("Couldnt save new user: " + err); | |
promise.fail(err); | |
return; | |
} | |
else{ | |
console.log("User wasnt existant, it is now created: " + JSON.stringify(joiningUser)); | |
promise.fulfill(joiningUser); | |
} | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment