【问题标题】:Issue with connect-mongo, passport & passport-local-mongoose with session not persistingconnect-mongo、passport 和 passport-local-mongoose 问题,会话不持久
【发布时间】:2018-12-13 06:46:26
【问题描述】:

尝试保存会话并具有 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

任何帮助将不胜感激

【问题讨论】:

    标签: 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);
    

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 2013-07-23
      • 2021-08-15
      • 2018-02-08
      • 2018-11-07
      相关资源
      最近更新 更多