连接mongo,护照和护照本地猫鼬的问题,会话未持久

时间:2018-07-04 20:06:34

标签: node.js typescript express mongoose passport.js

试图保存会话并具有req.isAuthenticated(),req.user等功能,但无法使其正常工作。

会话无法持续,只是由于某种原因而无法正常工作。

app.ts https://pastebin.com/yGvUZhud

Some Code

routes.ts https://pastebin.com/8Q2h1hsK

Some Code

controller.ts https://pastebin.com/9iU6iHn9

Some Code

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

发现我需要调用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);
相关问题