<commit_before>import jwt from 'jsonwebtoken';
import errors from 'feathers-errors';

/**
 * Verifies that a JWT token is valid
 * 
 * @param  {Object} options - An options object
 * @param {String} options.secret - The JWT secret
 */
export default function(options = {}){
  const secret = options.secret;

  return function(hook) {
    const token = hook.params.token;

    if (!token) {
      return Promise.resolve(hook);
    }

    return new Promise(function(resolve, reject){
      jwt.verify(token, secret, options, function (error, payload) {
        if (error) {
          // Return a 401 if the token has expired or is invalid.
          return reject(new errors.NotAuthenticated(error));
        }
        
        // Attach our decoded token payload to the params
        hook.params.payload = payload;

        resolve(hook);<commit_msg>Throw an error if you don't pass a secret to verifyToken hook<commit_after>import jwt from 'jsonwebtoken';
import errors from 'feathers-errors';

/**
 * Verifies that a JWT token is valid
 * 
 * @param  {Object} options - An options object
 * @param {String} options.secret - The JWT secret
 */
export default function(options = {}){
  const secret = options.secret;

  if (!secret) {
    console.log('no secret', options);
    throw new Error('You need to pass `options.secret` to the verifyToken() hook.');
  }

  return function(hook) {
    const token = hook.params.token;

    if (!token) {
      return Promise.resolve(hook);
    }

    return new Promise(function(resolve, reject){
      jwt.verify(token, secret, options, function (error, payload) {
        if (error) {
          // Return a 401 if the token has expired or is invalid.
          return reject(new errors.NotAuthenticated(error));
        }
        
        // Attach our decoded token payload to the params
        hook.params.payload = payload;

        resolve(hook);
{'fraction_non_alphanumeric': 0.10654008438818566, 'fraction_numerical': 0.0031645569620253164, 'mean_word_length': 2.734251968503937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2101401', 'n_tokens_mistral': 543, 'n_tokens_neox': 523, 'n_words': 184}