Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda