【问题标题】:Issue with connect-mongo, passport & passport-local-mongoose with session not persistingconnect-mongo、passport 和 passport-local-mongoose 问题,会话不持久
【发布时间】:2018-12-13 06:46:26
【问题描述】:
【问题讨论】:
标签:
node.js
typescript
express
mongoose
passport.js
【解决方案1】:
发现我需要调用 passport.authenticate 作为路由的中间件,并且必须进行路由链接才能正常工作!
app.route('/authenticate')
.post(passport.authenticate('local'))
.post((req: Request, res: Response, next: NextFunction) => {
try {
console.log(chalk.cyanBright('Request from: ') + chalk.yellowBright(req.originalUrl));
console.log(chalk.cyanBright('Request type: ') + chalk.yellowBright(req.method));
next();
} catch (error) {
console.error(chalk.redBright(error));
}
}, this.authenticationController.authenticate);