search

Home  >  Q&A  >  body text

How does express use session?

The problems are explained one by one. Because the relationship is relatively close, it is considered a problem. It is a big problem and there is nothing wrong with it.
project description:

        1.express项目,直接命令行初始化项目结构。
        2.目录结构如上图:
        3.网站功能:用户注册登录,session验证用户身份。
        4.verify.js写的用户验证逻辑。

Question 1: Why does the value of sessionID change with every request? So there is no way to add your own custom value to req.session. I read on the Internet that it is enough to use redis for storage, and then use redis for storage. But another problem occurred. req.session.regenerate() cannot be used in verify.js. The error message is: There is no regenerate property. Why use redis to destroy someone's own methods?
Question 2: I checked on the Internet again, and it was said that it was because of the session var session = require('express-session'); in app.js, and In verify.js, var session = require('express-session');, because require is required twice, the req.session in the two files is actually not the same object. I can't figure it out. Why are the same req.session different when I operate it? I tried const session = require('express-session'); as answered by others on the Internet, but it still didn't solve the problem.

I've almost fainted from this session in the past two days. I'm a front-end newbie, please give me some answers. Thank you in advance!

Background supplement:

      1.用户的登录验证完全没有问题。
      2.app.js里面的session初始化已经放在了路由之前。

To write session verification, basically refer to the following content:
/a/11...
http://www.cnblogs.com/chying...
http://wiki. jikexueyuan.com/p...
express-session official document

phpcn_u1582phpcn_u15822752 days ago499

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:38:03

    cookie-parsersignedCookiecan do signature verification, and express-session hosts the creation and storage of sessions.

    reply
    0
  • Cancelreply