我已经使用客户端会话npm创建了会话。
res.header似乎工作正常,因为令牌已作为雇主对象的一部分生成。问题是页面无法重定向!
app.post('/employer/signIn', (req, res) => {
var employer = new Employer({
email: req.body.employer__sign_in_email,
password: req.body.employer__sign_in_password
});
employer.save().then(() => {
req.session.employer = employer;
var func = employer.generateAuthToken();
return [req.session.employer, func];
}).then((token) => {
res.header('x-auth', token).redirect("/employer/home/home.html");
}).catch((e) => res.status(400).send(e));
});