Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

754
Vistas
TypeError: JwtStrategy requires a secret or key, runs on Windows but not on Mac

I am trying to use passport for my javascript code. However, I am getting a "JwtStrategy requires a secret or key error". I am collaborating with my friend on this. While his runs fine, mine does not and I'm not sure why. He uses windows while I use a mac, for reference.

Our code for jwt.js:

const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;

var User = require("./models/user");

const opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = process.env.JWT_SECRET_KEY;

module.exports = new JwtStrategy(opts, async (jwt_payload, done) => {
  const user = await User.findOne({email: jwt_payload.email});
  if (!user) {
    return done(null, false)
  }
  return done(null, user);
}) 

The error message:

TypeError: JwtStrategy requires a secret or key
    at new JwtStrategy (/Users/editedUser/Desktop/frods/server/node_modules/passport-jwt/lib/strategy.js:45:15)
    at Object.<anonymous> (/Users/editedUser/Desktop/frods/server/jwt.js:10:18)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/editedUser/Desktop/frods/server/app.js:9:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Update: It was a stupid mistake(?) on my part. When I saved the .env files, they were in the .crash format. It was showing up in my finder as .env, but in the command line, it was showing up as

.env.crash

I had to rename it as

mv .env.crash .env

for it to work

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda