作者:欧阳火凡 | 来源:互联网 | 2023-02-05 16:41
SowhatImtryingtodoiswhensomeoneloadsmysite,andgetsauthenticatedbypassport,theirus
So what I'm trying to do is when someone loads my site, and gets authenticated by passport, their userId is stored in req.user.id
in my app.get('/home', funciton(req, res)
. Now what I am trying to do in a way is this:
所以我想要做的是当有人加载我的网站并通过护照进行身份验证时,他们的userId存储在我的app.get('/ home',funciton(req,res)中的req.user.id中。现在我想在某种程度上做的是这样的:
app.get('/home'. function(req, res){
io.on('connection', function(socket){
socket.emit('userId', req.user.id);
});
}
Thats essentially what I'm trying to do, but I know it is very wrong. Now my question is how can I get the req.user.id
to the client so I can use it in future interactions with the server.
这基本上就是我想要做的,但我知道这是非常错误的。现在我的问题是如何将req.user.id提供给客户端,以便我可以在将来与服务器交互时使用它。
2 个解决方案