I am having trouble getting the 'req.user._id' of a user after the user connected to the server with socket.IO. Here's the code:Server-side:const io = require('socket.io')(); // middleware io.use((socket, next) => { if (req.user._id === '123abc'){ //Not sure how to obtain req.user._id in this case return next(); } return next(new Error('authentication error')); }); I can usually get the 'user._id' when a user requested through an express.js route. However in this case, the user connects through socket.io, so I am not too sure how to obtain the user's id.
Submitted September 16, 2018 at 09:48AM by VickNicks
No comments:
Post a Comment