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

249
Views
error while constructing my authorisation with jwt

I am getting an error from this code and trying to resolve it. I am trying to follow a tutorial for the same, but they don't have this error either on the messages.

// authentication middleware
const passport = require("passport");

// how are we going to aunhtenticating
const LocalStatregy = require("passport-local").Strategy;

const JwtStatregy = require("passport-jwt");
const User = require("./models/User");

const cookieExtractor = (req) => {
  let token = null;
  if (req && req.cookies) {
    token = req.cookies["acess_token"];
  }
  return token;
};

// authorisation works to protect endpoints
passport.use(
  new JwtStatregy(
    {
      // uses custom function to find the cookie
      jwtFromRequest: cookieExtractor,
      // verifies token is legitimate
      secretOrKey: "NoobCoder",
      // payload means data we created
    },
    (payload, done) => {
      User.findById({ _id: payload.sub }, (err, user) => {
        if (err) return done(err, false);
        if (user) return done(null, user);
        else return done(null, false);
      });
    }
  )
);

I get the below error. I understand my problem is with my JwtStrategy, but how to fix this? That is not a constructor itself, I tried using Promise, and constructor word but it didn't work.

[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
C:\Users\Sini\Documents\SurfApp\backend\passport.js:20
  new JwtStatregy(
  ^

TypeError: JwtStatregy is not a constructor
    at Object.<anonymous> (C:\Users\Sini\Documents\SurfApp\backend\passport.js:20:3)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\Sini\Documents\SurfApp\backend\routes\User.js:5:24)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
[nodemon] app crashed - waiting for file changes before starting...
about 4 years ago · Juan Pablo Isaza
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!