Lev Lev - 5 months ago 60
Javascript Question

Passport LocalStrategy inconsistent class name

I'm creating a strategy object like this :

var strat = new LocalStrategy({
usernameField: 'email'
function(username, password, done) {
User.findOne({ email: username }, function (err, user) {
if (err) { return done(err); }
// Return if user not found in database
if (!user) {
return done(null, false, {
message: 'User not found'
// Return if password is wrong
if (!user.validPassword(password)) {
return done(null, false, {
message: 'Password is wrong'
// If credentials are correct, return the user object
return done(null, user);

In my debugger, I see that the strat object is an instance of Class "Strategy".

enter image description here

Shouldn't it be an instance of "LocalStrategy" since it was created via LocalStrategy conscructor ?


The following is an example piece of code of what is normally do to setup passportjs using local strategy

var LocalStrategy   = require('passport-local').Strategy;

As you can see Strategy is the name of the exported symbol and the name of the strategy constructor. LocalStrategy is just the name of a local variable you are using.