Mam problem z modułem Passport.js i Express.js.
To jest mój kod i chcę tylko użyć zakodowanego logowania przy pierwszej próbie.
Zawsze dostaję wiadomość:
Szukałem dużo i znalazłem kilka postów w stackoverflow, ale nie udało mi się.
Error: failed to serialize user into session
at pass (c:\Development\private\aortmann\bootstrap_blog\node_modules\passport\lib\passport\index.js:275:19)
Mój kod wygląda tak.
'use strict';
var express = require('express');
var path = require('path');
var fs = require('fs');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var nodemailer = require('nodemailer');
var app = express();
module.exports = function setupBlog(mailTransport, database){
var config = JSON.parse(fs.readFileSync('./blog.config'));
app.set('view options', {layout: false});
app.use(express.static(path.join(__dirname, '../', 'resources', 'html')));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: 'secret' }));
app.use(passport.initialize());
app.use(passport.session());
app.get('/blog/:blogTitle', function(req, res) {
var blogTitle = req.params.blogTitle;
if(blogTitle === 'newest'){
database.getLatestBlogPost(function(post) {
res.send(post);
});
} else {
database.getBlogPostByTitle(blogTitle, function(blogPost) {
res.send(blogPost);
});
}
});
passport.use(new LocalStrategy(function(username, password, done) {
// database.login(username, password, done);
if (username === 'admin' && password === 'admin') {
console.log('in');
done(null, { username: username });
} else {
done(null, false);
}
}));
app.post('/login', passport.authenticate('local', {
successRedirect: '/accessed',
failureRedirect: '/access'
}));
app.listen(8080);
console.log('Blog is running on port 8080');
}();
Dzięki.