lib/engine.js
function(attributes, user, cb){
      var self = this;
      attributes.user = user.id;

      waterlock.User.findOne(user.id).exec(function(err, user){
        if(err){
          waterlock.logger.debug(err);
          return cb(err);
        }

        if(user.auth){
          delete(attributes.auth);
          //update existing auth
          waterlock.Auth.findOne(user.auth).exec(function(err, auth){
            if(err){
              waterlock.logger.debug(err);
              return cb(err);
            }

            // Check if any attribtues have changed if so update them
            if(self._updateAuth(auth, attributes)){
               auth.save(function(err){
                if(err){
                  waterlock.logger.debug(err);
                  return cb(err);
                }
                user.auth = auth;
                cb(err, user);
              });
            }else{
              user.auth = auth;
              cb(err, user);
            }

          });
        }else{
          // force create by pass of user id
          self.findOrCreateAuth(user.id, attributes, cb);
        }
      });
    }
function(attributes, user, cb){
      var self = this;
      attributes.user = user.id;

      waterlock.User.findOne(user.id).exec(function(err, user){
        if(err){
          waterlock.logger.debug(err);
          return cb(err);
        }

        if(user.auth){
          delete(attributes.auth);
          //update existing auth
          waterlock.Auth.findOne(user.auth).exec(function(err, auth){
            if(err){
              waterlock.logger.debug(err);
              return cb(err);
            }

            // Check if any attribtues have changed if so update them
            if(self._updateAuth(auth, attributes)){
               auth.save(function(err){
                if(err){
                  waterlock.logger.debug(err);
                  return cb(err);
                }
                user.auth = auth;
                cb(err, user);
              });
            }else{
              user.auth = auth;
              cb(err, user);
            }

          });
        }else{
          // force create by pass of user id
          self.findOrCreateAuth(user.id, attributes, cb);
        }
      });
    }
function ( attributes , user , cb ) { var self = this ; attributes . user = user . id ; waterlock . User . findOne ( user . id ) . exec ( function ( err , user ) { if ( err ) { waterlock . logger . debug ( err ) ; return cb ( err ) ; } if ( user . auth ) { delete ( attributes . auth ) ; //update existing auth waterlock . Auth . findOne ( user . auth ) . exec ( function ( err , auth ) { if ( err ) { waterlock . logger . debug ( err ) ; return cb ( err ) ; } // Check if any attribtues have changed if so update them if ( self . _updateAuth ( auth , attributes ) ) { auth . save ( function ( err ) { if ( err ) { waterlock . logger . debug ( err ) ; return cb ( err ) ; } user . auth = auth ; cb ( err , user ) ; } ) ; } else { user . auth = auth ; cb ( err , user ) ; } } ) ; } else { // force create by pass of user id self . findOrCreateAuth ( user . id , attributes , cb ) ; } } ) ; }
Attach given auth attributes to user

@param  {Object}   attributes auth attributes
@param  {Object}   user       user instance
@param  {Function} cb         function to be called when the auth has been
attached or an error has occurred
@api public
Attach given auth attributes to user