基本node.js表示authentication不起作用

我是新的node.js身份validation。 我想用护照,护照本地,做一些基本的authentication。 但是,当我尝试它,它总是去authentication失败。

我正在按照这个教程http://www.sitepoint.com/local-authentication-using-passport-node-js/

这是我迄今为止:

var express = require('express'); var app = express(); var qs = require('querystring'); var pg = require('pg'); var passport = require('passport'); var LocalStrategy = require('passport-local').Strategy; //var expressSession = require('express-session'); //app.use(expressSession({secret: 'mySecretKey', cookie: { maxAge: 60000 }, resave: true, saveUninitialized: true})); app.use(passport.initialize()); app.use(passport.session()); app.use(express.static(__dirname + '/public')); passport.serializeUser(function(user, done) { done(null, user); }); passport.deserializeUser(function(user, done) { done(null, user); }); // in here I know I am supposed to connect to database, and check if the username,password is there, but for now, i'll just force it to return a user, like they exist. passport.use(new LocalStrategy(function(username, password, done) { console.log(1); // does not even print this //return done(null, false); var r = done(null, { 'username': username, 'password': password }); console.log(r); return r; })); /* * Visit the home page. */ app.get('/', function (req, res) { var dest = 'index.html'; res.sendFile(dest, { root: __dirname }); }); /* * Login. */ app.post('/login', passport.authenticate('local', { successRedirect: '/loginSuccess.html', failureRedirect: '/loginFailure.html' }) ); var server = app.listen(process.env.PORT || 3000, function () { var host = server.address().address; var port = server.address().port; console.log('My App started at http://%s:%s', host, port); }); 

有谁知道这有什么问题?

也有人可以解释这个基本authentication是如何工作的,以及serialize / deserialize函数是用来做什么的?

谢谢

       

网上收集的解决方案 "基本node.js表示authentication不起作用"