我为用户身份验证编写套接字中间件,但我不知道我的问题是什么!在 android 端“未经授权”事件未调用。
服务器端 :
async function (socket, next) {
if (socket.handshake.query && socket.handshake.query.token) {
jwt.verify(socket.handshake.query.token, process.env.SECRET_JWT_KEY, function (err, decoded) {
if (err) {
socket.emit( "unauthorized", "unauthorized user") <==send to sender you'r authentication is failed
console.log("Query: ", "unauthorized"); <==This line is lunched
return next(new Error('Authentication error'));
}
socket.decoded = decoded;
next();
});
} else {
next(new Error('Authentication error'));
}
客户端 :
val socket = IO.socket("http://192.168.1.6:3000", IO.Options().apply {
path = "/sockets/chat"
query = "token=wrongtoken"
})
socket.on("unauthorized", object : Emitter.Listener { <== THIS NOT LUNCED!!
override fun call(vararg args: Any?) {
println("user authentication failed" )
}
}
qq_遁去的一_1
蛊毒传说
相关分类