express.js函数会在会话中清除
我想将用户类放入会话中,以便可以在任何地方使用它。
但是问题在于,我目前无法做到这一点,当我将自定义类型放入会话(例如函数)中时,它似乎只是删除它们,这是我现在正在编码的内容。
这是一个演示
async function newRequest(req, res)
{
if (!req.session.user)
req.session.user = new User.Instance(sql);
console.log(typeof await req.session.user.loginsValid)
if (req.session.user.authentified && await req.session.user.loginsValid())
router = new Router("Connected");
else
router = new Router("Disconnected");
router.Start(req, res, sql);
}
,这是加载页面2倍后的输出
root@networkconf:/home#node app.js
功能
未定义
I would like to put a User class inside my session so I would be able to use it anywhere.
But the problem is that I currently cannot do that, when I put custom types inside my session such as Functions, it seems to just remove them, which is a need for what I am coding right now.
Here is a demonstration
async function newRequest(req, res)
{
if (!req.session.user)
req.session.user = new User.Instance(sql);
console.log(typeof await req.session.user.loginsValid)
if (req.session.user.authentified && await req.session.user.loginsValid())
router = new Router("Connected");
else
router = new Router("Disconnected");
router.Start(req, res, sql);
}
here is the output after loading 2 times the page
root@networkConf:/home# node app.js
function
undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论