function createToken(user) {
  console.log('creating Token for:', user)
  let scopes = ['user'];
  if (user.isAdmin) {
    scopes.push('admin');
  }
  if (user.isOwner) {
    scopes.push('admin');
  }
  if (user.isTrainer) {
    scopes.push('admin');
  }
  if (user.isCustomer) {
    scopes.push('admin');
  }

  console.log('USER ID:', user.id)
  const payload = {
    sub: user.id,
    iat: moment().unix(),
    exp: moment().add(14, 'days').unix(),
    scopes,
  };
  console.log(payload, secrets.TOKEN_SECRET)
  return jwt.encode(payload, secrets.TOKEN_SECRET);
}
/**
 * Creates a JSON Web Token given a complete user. JWT contains user id,
 * expiration and user's access scopes.
 *
 * @param {object} user - A user info, as extracted from the database
 */
Creates a JSON Web Token given a complete user. JWT contains user id,
expiration and user's access scopes.

@param {object} user - A user info, as extracted from the database
Creates a JSON Web Token given a complete user . JWT contains user id expiration and user ' s access scopes . @param { object } user - A user info as extracted from the database
function createToken(user) {
  console.log('creating Token for:', user)
  let scopes = ['user'];
  if (user.isAdmin) {
    scopes.push('admin');
  }
  if (user.isOwner) {
    scopes.push('admin');
  }
  if (user.isTrainer) {
    scopes.push('admin');
  }
  if (user.isCustomer) {
    scopes.push('admin');
  }
  console.log('USER ID:', user.id)
  const payload = {
    sub: user.id,
    iat: moment().unix(),
    exp: moment().add(14, 'days').unix(),
    scopes,
  };
  console.log(payload, secrets.TOKEN_SECRET)
  return jwt.encode(payload, secrets.TOKEN_SECRET);
}
function createToken ( user ) { console . log ( 'creating Token for:' , user ) let scopes = [ 'user' ] ; if ( user . isAdmin ) { scopes . push ( 'admin' ) ; } if ( user . isOwner ) { scopes . push ( 'admin' ) ; } if ( user . isTrainer ) { scopes . push ( 'admin' ) ; } if ( user . isCustomer ) { scopes . push ( 'admin' ) ; } console . log ( 'USER ID:' , user . id ) const payload = { sub : user . id , iat : moment ( ) . unix ( ) , exp : moment ( ) . add ( 14 , 'days' ) . unix ( ) , scopes , } ; console . log ( payload , secrets . TOKEN_SECRET ) return jwt . encode ( payload , secrets . TOKEN_SECRET ) ; }
Creates a JSON Web Token given a complete user.
Creates a JSON Web Token given a complete user .