mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.96k stars 213 forks source link

JwtStrategy TypeError v4.0.0 #156

Closed MonizDave closed 6 years ago

MonizDave commented 6 years ago

I can't see what I'm doing wrong

Error: /node_modules/passport-jwt/lib/strategy.js:55 throw new TypeError('JwtStrategy requires a function to retrieve jwt from requests (see option jwtFromRequest)');

Code:

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

const User = require('../models/user');

/* ----------------------------------------------------------------------------- */
module.exports = function (passport) {
    let options = {};
    options.JwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
    options.secretOrKey = config.secret;

    passport.use(new JwtStrategy(options, function (jwt_payload, done) {
        User.getUserById(jwt_payload.data._id, (error, user) => {
            if (error)
                return done(error, false);
            if (user)
                return done(null, user);
            else
                return done(null, false);
        });
    }));
};
MonizDave commented 6 years ago

options.JwtFromRequest -> uppercase J....

What a rookie! Sorry for wasting your time.

houssamboudiar commented 6 years ago

MonizDave: you wasted your time anyway rudeness is not useful

MonizDave commented 6 years ago

@houssamboudiar: please read before commenting.

I was the original poster, I found my own mistake, and I called myself a rookie... - and I was apologizing for wasting other people's time because my bug was my own fault.

At no point was there any rudeness.... In fact the only rude thing here is that you gave me a thumbs down without paying proper attention.

Also, this was closed 4 months ago - why did you even come here?

houssamboudiar commented 6 years ago

xD I had the same error I came seeking a solution your thread was the first to check but your answer was ambiguous I wasted 1hour on it :( rookie me you could ve just say turn J to j and sorry for my rudeness

Brkkc06 commented 1 month ago

My friend, thank you very much. If I had looked at other forums, it would have taken me 1-2 hours and I would have tried different codes. You helped me with just a simple explanation. God bless you.