Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

753
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!