src/models/user.js
function generateBearerToken(tokenSecret, expiresInMinutes = 60 * 24 * 14, scope = []) {
  if (!tokenSecret) {
    throw new Error('Token secret is undefined');
  }

  const data = {
    user: this._id.toString(),
  };

  if (scope.length) {
    data.scope = scope;
  }

  const token = jwt.sign(data, tokenSecret, {
    expiresInMinutes,
  });

  return {
    type: 'Bearer',
    value: token,
  };
}
function generateBearerToken(tokenSecret, expiresInMinutes = 60 * 24 * 14, scope = []) {
  if (!tokenSecret) {
    throw new Error('Token secret is undefined');
  }

  const data = {
    user: this._id.toString(),
  };

  if (scope.length) {
    data.scope = scope;
  }

  const token = jwt.sign(data, tokenSecret, {
    expiresInMinutes,
  });

  return {
    type: 'Bearer',
    value: token,
  };
}
function generateBearerToken ( tokenSecret , expiresInMinutes = 60 * 24 * 14 , scope = [ ] ) { if ( ! tokenSecret ) { throw new Error ( 'Token secret is undefined' ) ; } const data = { user : this . _id . toString ( ) , } ; if ( scope . length ) { data . scope = scope ; } const token = jwt . sign ( data , tokenSecret , { expiresInMinutes , } ) ; return { type : 'Bearer' , value : token , } ; }
Generate access token for actual user
@param  {String} Secret for generating of token
@param  {[Number]} expiresInMinutes
@param  {[Array]} scope List of scopes
@return {Object} Access token of user
Generate access token for actual user