Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- });
- }
- });
- };
Add Comment
Please, Sign In to add comment