node.js - Passport-Local Authenticate callback -


i'm following guide works fine, , use of passport middleware this:

//app.js var account = require('./models/account'); passport.use(new localstrategy(account.authenticate()));  //account.js var mongoose = require('mongoose'); var schema = mongoose.schema; var passportlocalmongoose = require('passport-local-mongoose');  var account = new schema({     username: string,     password: string });  account.plugin(passportlocalmongoose);  module.exports = mongoose.model('account', account); 

that works fine, want change more specific, if authentication can't find user or errors or something, can else (like return error message example).

looking @ passport-local website see this, have no idea how convert top code code below. tried. or maybe they're not same thing , i'm banging head on wall no reason? can me out? still want able use code have in "account.js" code above different actions based on whether it's been authenticated, user doesn't exist etc.

passport.use(new localstrategy(function(username, password, done) {     user.findone({ username: username }, function (err, user) {         if (err) {  //error interacting database             return done(err);         }          if (!user) {   //cannot find user             return done(null, false);          }          if (!user.verifypassword(password)) {  // passwords don't match?             return done(null, false);          }          return done(null, user);     });   } )); 


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -