You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a middleware to check the socket user with JWT, and it is working good for socket.io. io-auth-check.js
constjwt=require('jsonwebtoken')constUser=require('mongoose').model('User')constconfig=require('../../config')/** * The Auth Checker middleware function. */module.exports=(socket,next)=>{if(socket.handshake.query&&socket.handshake.query.token){jwt.verify(socket.handshake.query.token,config.jwtSecret,(err,decoded)=>{// the 401 code is for unauthorized statusif(err){console.log(err)returnnext(newError('Authentication error'))}constuserId=decoded.subsocket.decoded=decoded// check if a user existsreturnUser.findById(userId,(userErr,user)=>{if(userErr||!user){returnnext(newError('Authentication error , cannot find the user'))}console.log(user.familly_name+' is connected')console.log('token thing works fine')socket.user=userreturnnext()})})}next(newError('Authentication error'))}
index.js
module.exports=(io)=>{varmongoose=require('mongoose')varss=require('socket.io-stream')varent=require('ent')// Permet de bloquer les caractères HTML (sécurité équivalente à htmlentities en PHP)varGrid=require('gridfs-stream')Grid.mongo=mongoose.mongovargfsconstUniversity=require('mongoose').model('University')varioAuthCheck=require('../middleware/io-auth-check')mongoose.connection.once('open',function(){gfs=Grid(mongoose.connection.db)})// Note sure about thisio.use(ioAuthCheck).on('connection',function(socket){
The problem is that I got the error specified in the title:
If I do disable my middleware, I do not have the error. So it is related to it. I need my middleware . What do you think I could do to resolve this issue ? Is there anything I did wrong ?
Best regards,
Arn
The text was updated successfully, but these errors were encountered:
Hei. Okay it is weird, but to upload a file, I need to push mu button two times, or write into the chat I put on the same page. It looks like I am missing a next() or something . I don't know. I keep trying to figure out.
Hello.
I am using React Node.js webpack and socket.io + socket.io-stream. And I am new to this.
I like a lot socket.io-stream because it is easy to use and I all the time get good results. But I do have a bug now.
I have the following code :
I have a middleware to check the socket user with JWT, and it is working good for socket.io.
io-auth-check.js
index.js
The problem is that I got the error specified in the title:
Uncaught Error: Uncaught, unspecified "error" event. (Authentication error)
at Socket.EventEmitter.emit (events.js:62)
at Socket. (index.js:21)
at Socket.Emitter.emit (index.js:133)
at Socket.emit (socket.js:136)
at Socket.onpacket (socket.js:248)
at Manager. (index.js:21)
at Manager.Emitter.emit (index.js:133)
at Manager.ondecoded (manager.js:345)
at Decoder. (index.js:21)
at Decoder.Emitter.emit (index.js:133)
EventEmitter.emit @ events.js:62
(anonymous) @ index.js:21
Emitter.emit @ index.js:133
Socket.emit @ socket.js:136
Socket.onpacket @ socket.js:248
(anonymous) @ index.js:21
Emitter.emit @ index.js:133
Manager.ondecoded @ manager.js:345
(anonymous) @ index.js:21
Emitter.emit @ index.js:133
Decoder.add @ index.js:241
Manager.ondata @ manager.js:335
(anonymous) @ index.js:21
Emitter.emit @ index.js:133
Socket.onPacket @ socket.js:457
(anonymous) @ socket.js:274
Emitter.emit @ index.js:133
Transport.onPacket @ transport.js:145
callback @ polling.js:144
exports.decodePayload @ browser.js:418
Polling.onData @ polling.js:148
(anonymous) @ polling-xhr.js:125
Emitter.emit @ index.js:133
Request.onData @ polling-xhr.js:299
Request.onLoad @ polling-xhr.js:366
xhr.onreadystatechange @ polling-xhr.js:252
If I do disable my middleware, I do not have the error. So it is related to it. I need my middleware . What do you think I could do to resolve this issue ? Is there anything I did wrong ?
Best regards,
Arn
The text was updated successfully, but these errors were encountered: