src/lib/db.js
function createToken(username, done) {
  return getUser(username, function(getUserErr, user) {
    if (getUserErr) {
      return done(getUserErr);
    }

    if (!user) {
      return done(new Error(`user '${username}' not found`));
    }

    const token = uuid.v4();

    return hashToken(token, function(cryptErr, hash) {
      if (cryptErr) {
        return done(cryptErr);
      }

      return getModels(function(m) {
        m.collections.token.create({
          uuid: hash,
          owner: user.id,
        }, function(createTokenErr) {
          if (createTokenErr) {
            return done(createTokenErr);
          }

          return done(null, token);
        }); // m.collections.token.create
      }); // getModels
    }); // hashToken
  }); // getUser
}
function createToken(username, done) {
  return getUser(username, function(getUserErr, user) {
    if (getUserErr) {
      return done(getUserErr);
    }

    if (!user) {
      return done(new Error(`user '${username}' not found`));
    }

    const token = uuid.v4();

    return hashToken(token, function(cryptErr, hash) {
      if (cryptErr) {
        return done(cryptErr);
      }

      return getModels(function(m) {
        m.collections.token.create({
          uuid: hash,
          owner: user.id,
        }, function(createTokenErr) {
          if (createTokenErr) {
            return done(createTokenErr);
          }

          return done(null, token);
        }); // m.collections.token.create
      }); // getModels
    }); // hashToken
  }); // getUser
}
function createToken ( username , done ) { return getUser ( username , function ( getUserErr , user ) { if ( getUserErr ) { return done ( getUserErr ) ; } if ( ! user ) { return done ( new Error ( ` ${ username } ` ) ) ; } const token = uuid . v4 ( ) ; return hashToken ( token , function ( cryptErr , hash ) { if ( cryptErr ) { return done ( cryptErr ) ; } return getModels ( function ( m ) { m . collections . token . create ( { uuid : hash , owner : user . id , } , function ( createTokenErr ) { if ( createTokenErr ) { return done ( createTokenErr ) ; } return done ( null , token ) ; } ) ; // m.collections.token.create } ) ; // getModels } ) ; // hashToken } ) ; // getUser }
Create a token for a user. A token is simply a v4 uuid.

@param {String} username
@param {Function} done - done(err, token)
Create a token for a user . A token is simply a v4 uuid .