title: Why do I get error JwtStrategy requires a secret or key?
body: <p>I get this error "TypeError: JwtStrategy requires a secret or key" and I can't figure out how to fix it. What can I do to fix it?</p>
  
  <pre><code>(node:46218) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [Bus]. Use emitter.setMaxListeners() to increase limit
  /mnt/data/Workspace/Development/comichaven/api/node_modules/passport-jwt/lib/strategy.js:45
          throw new TypeError('JwtStrategy requires a secret or key');
          ^
  
  TypeError: JwtStrategy requires a secret or key
      at new JwtStrategy (/mnt/data/Workspace/Development/comichaven/api/node_modules/passport-jwt/lib/strategy.js:45:15)
      at module.exports (/mnt/data/Workspace/Development/comichaven/api/config/passport.js:14:9)
      at Object.&lt;anonymous&gt; (/mnt/data/Workspace/Development/comichaven/api/server.js:40:29)
      at Module._compile (internal/modules/cjs/loader.js:956:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
      at Module.load (internal/modules/cjs/loader.js:812:32)
      at Function.Module._load (internal/modules/cjs/loader.js:724:14)
      at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
      at internal/main/run_main_module.js:17:11
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  
  <p>What I have tried</p>
  
  <ul>
  <li>renaming the varable opts</li>
  <li>checked so the variables are named the same</li>
  <li>tried using dotenv</li>
  <li>replacing keys.secretOrKey with a string</li>
  </ul>
  
  <p>passport.js</p>
  
  <pre><code>const JwtStrategy = require('passport-jwt').Strategy;
  const ExtractJwt = require('passport-jwt').ExtractJwt;
  const mongoose = require('mongoose');
  const User = mongoose.model("users");
  const keys = require("./keys")
  
  const opts = {};
  
  opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
  opts.secretKey = keys.secretOrKey;
  
  module.exports = passport =&gt; {
      passport.use(
          new JwtStrategy(opts, (jwt_payload, done) =&gt; {
              User.findById(jwt_payload.id)
              .then(user =&gt; {
                  if (user) {
                      return done(null, user)
                  }
                  return done(null, false)
              })
              .catch(err =&gt; {
                  console.log(err)
              });
          })
      )
  }
  </code></pre>
  
  <p>keys.js</p>
  
  <pre><code>module.exports = {
      secretOrKey: 'secret'
  };
  </code></pre>