mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.97k stars 214 forks source link

JWT Passport authentication middleware never called! #203

Closed CYB3RL1F3 closed 4 years ago

CYB3RL1F3 commented 4 years ago

Hello,

Here is my code, maybe I do it wrong?

Since I upgraded to jwt 4, it doesn't work anymore. I manage to login but when I try to access to the secured route, I directly go into the "secured" function, and the middleware is never called...

A clue?

app.use(passport.initialize());
const jwtstrategy = new JWTStrategy(
      {
         jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
         secretOrKey: __JWT__,
         passReqToCallback: true
      },
      async (req: Request, payload: AuthenticationPayload, done) => {
        console.log('>>>> SHOULD PASS HERE BUT DOESN'T !!!!!!!!');
      }
)
passport.use('jwt', jwtstrategy)
  app.get('/secured', passport.authenticate('jwt', {
      session: false,
      failureRedirect: "/forbidden"
    }), (req, res...)
CYB3RL1F3 commented 4 years ago

Finally it was an error in my code, everything works well, sorry for the issue.