passport.js在新的LocalStrategy上返回Type Error

时间:2014-02-19 03:05:03

标签: javascript node.js passport.js

在node.js上运行护照,并在启动时返回此

/Users/josh/Dropbox/Development/headstart/config/middleware.js:27 passport.use(new LocalStrategy(function(username,password,done){ ^ TypeError: object is not a function at Function.<anonymous> (/Users/josh/Dropbox/Development/headstart/config/middleware.js:27:18) at Function.app.configure (/Users/josh/Dropbox/Development/headstart/node_modules/express/lib/application.js:391:61) at module.exports (/Users/josh/Dropbox/Development/headstart/config/middleware.js:6:7) at Object.<anonymous> (/Users/josh/Dropbox/Development/headstart/index.js:32:31)

我的代码看起来很好并且正在传递lint

我的中间件代码

```

passport.use(new LocalStrategy(function(username,password,done){
  log.info(username+"//"+password+" is trying to login as local.");
  var userModel = mongoose.model('users',userSchema);
  userModel.findOne({'username':username})
  .exec(function(err,puser){
    if(err){log.info(err.stack);}
    if(!puser){
      log.info("user not found.");
      return done(null, false, { message: 'Unknown user ' + username });
    }
    if (password!==puser.password) {
      log.info("password invalid.");
      return done(null, false, { message: 'Invalid password' });
    } 
  return done(null, puser);
  });
}));

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});

app.use(express.bodyParser());
app.use(express.session({ secret: 's3cr3t' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
app.use(app.router);
app.use(logErrors);
app.use(clientErrorHandler);
app.use(errorHandler);
app.engine('ejs', require('ejs-locals'));
app.set('view engine', 'ejs');
app.set('views', '/app/views');
app.use(express.static('/public'));
app.use(express.favicon('/public/img/favicon.ico'));

0 个答案:

没有答案