index.js
function (req, res, next) {
    var prifile = req.profile;
    var filter = { or: [{ twitter: profile.user_id }, { email: profile.email }] };

    User.find({ where: filter }, function(err, users) {
      var user = users[0];

      if (user) {
        if (!user.twitter) {
          user.twitter = profile.user_id;
          user.displayName = user.displayName || profile.name;
          user.save(function() {
            req.user = user;
            next();
          });
          return;
        }

        req.user = user;
        next();
        return;
      }

      User.create({
        displayName: profile.name,
        yahoo: profile.user_id,
        email: profile.email,
        password: profile.user_id
      }, function (err, user) {
        req.user = user;
        next();
      });

    });
  }
function (req, res, next) {
    var prifile = req.profile;
    var filter = { or: [{ twitter: profile.user_id }, { email: profile.email }] };

    User.find({ where: filter }, function(err, users) {
      var user = users[0];

      if (user) {
        if (!user.twitter) {
          user.twitter = profile.user_id;
          user.displayName = user.displayName || profile.name;
          user.save(function() {
            req.user = user;
            next();
          });
          return;
        }

        req.user = user;
        next();
        return;
      }

      User.create({
        displayName: profile.name,
        yahoo: profile.user_id,
        email: profile.email,
        password: profile.user_id
      }, function (err, user) {
        req.user = user;
        next();
      });

    });
  }
function ( req , res , next ) { var prifile = req . profile ; var filter = { or : [ { twitter : profile . user_id } , { email : profile . email } ] } ; User . find ( { where : filter } , function ( err , users ) { var user = users [ 0 ] ; if ( user ) { if ( ! user . twitter ) { user . twitter = profile . user_id ; user . displayName = user . displayName || profile . name ; user . save ( function ( ) { req . user = user ; next ( ) ; } ) ; return ; } req . user = user ; next ( ) ; return ; } User . create ( { displayName : profile . name , yahoo : profile . user_id , email : profile . email , password : profile . user_id } , function ( err , user ) { req . user = user ; next ( ) ; } ) ; } ) ; }
Step 4b. Create a new user account or return an existing one.
Step 4b . Create a new user account or return an existing one .