routes/AToken.js
/**
 * Attempts to find a token in the database with the decoded subject and
 * resolves with the result.
 */
Attempts to find a token in the database with the decoded subject and
resolves with the result.
Attempts to find a token in the database with the decoded subject and resolves with the result .
function validateToken(decoded) {
  var subject = decoded.sub;
  return new Promise(function(resolve, reject) {
    if (_.isUndefined(subject)) {
      var error = new rekt.BadRequest('Token needs subject field.');
      reject(error);
    }
    Token.findOne({
      subject: subject
    }, function(err, result) {
      if (err) {
        var error = new rekt.BadRequest('Invalid Token');
        console.log(['Invalid', ip, subject, url, verb].join(' | '));
        reject(error);
      } else if (result) {
        console.log('Requested by', subject);
        resolve(result);
      }
    });
  });
}
function validateToken ( decoded ) { var subject = decoded . sub ; return new Promise ( function ( resolve , reject ) { if ( _ . isUndefined ( subject ) ) { var error = new rekt . BadRequest ( 'Token needs subject field.' ) ; reject ( error ) ; } Token . findOne ( { subject : subject } , function ( err , result ) { if ( err ) { var error = new rekt . BadRequest ( 'Invalid Token' ) ; console . log ( [ 'Invalid' , ip , subject , url , verb ] . join ( ' | ' ) ) ; reject ( error ) ; } else if ( result ) { console . log ( 'Requested by' , subject ) ; resolve ( result ) ; } } ) ; } ) ; }
Attempts to find a token in the database with the decoded subject and
 resolves with the result.
Attempts to find a token in the database with the decoded subject and resolves with the result .