我知道找到了here这个问题的另一个答案但我不能让我的生活让我的req.user在使用angularjs时填充除undefined以外的任何东西。
我已尝试过cookieParser,包括cookieParser中的会话密码,确保我的快速会话的顺序在护照会话之前,我有用户序列化和反序列化。什么都行不通。
这是我的代码,希望有人可以帮忙!
var HelperController = require('./controllers/helpers.js');
app.use("/helper", HelperController);
var passport = require('passport');
var cookieParser = require('cookie-parser');
var session = require('express-session');
//PASSPORT
//=================================
app.use(cookieParser('keyboard cat'));
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
//To be used when user is created ********
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
//USER HOME REGISTER
//=================================
app.post('/register', function(req, res){
console.log(req.body);
User.register(new User({
username: req.body.username
}),
req.body.password,
function(err, user){
req.login(user, function(err){
if (err) {console.log(err); }
return res.json(user);
});
});
});
//USER HOME LOGIN
//=================================
app.post('/login', passport.authenticate('local'), function(req, res){
res.json(req.user);
});
//ROUTER SETUP
//=========================================
var express = require('express');
var router = express.Router();
router.get('/get-user', function(req, res){
var user = req.user;
console.log(user);
res.json({user: user});
});
module.exports = router;