Node.js 无法读取属性';指数';socketiojwt
我试图将socketio jwt模块添加到我的应用程序项目中,以检查身份验证。我尝试输入他们在文档网站上的最低默认代码。我运行应用程序时没有错误,但当我浏览到url时,cmd提示符上出现错误 TypeError:无法读取未定义的属性“indexOf” 在命名空间处。(C:\Users\anjelotti\Desktop\chat.io\node\u modules\so cketio jwt\lib\index.js:16:30) server.js上的代码Node.js 无法读取属性';指数';socketiojwt,node.js,express,socket.io,jwt,Node.js,Express,Socket.io,Jwt,我试图将socketio jwt模块添加到我的应用程序项目中,以检查身份验证。我尝试输入他们在文档网站上的最低默认代码。我运行应用程序时没有错误,但当我浏览到url时,cmd提示符上出现错误 TypeError:无法读取未定义的属性“indexOf” 在命名空间处。(C:\Users\anjelotti\Desktop\chat.io\node\u modules\so cketio jwt\lib\index.js:16:30) server.js上的代码 io.sockets.on('con
io.sockets.on('connect', socketioJwt.authorize({
secret: 'abcd',
timeout: 10000 // 10 seconds to send the authentication message
}))
.on('authenticated', (socket) => {
//this socket is authenticated, we are good to handle more events from it.
console.log(`hello! ${socket.decoded_token.name}`);
socket.on('load chat',function(data){
Chat.find({}, function(err, docs) {
if (err) throw err;
socket.emit('load chat', docs);
});
});
以及index.html上的代码
socket.on('connect', () => {
socket
.emit('authenticate', { token: jwt }) //send the jwt
.on('authenticated', () => {
//do other things
})
.on('unauthorized', (msg) => {
console.log(`unauthorized: ${JSON.stringify(msg.data)}`);
throw new Error(msg.data.type);
})
});
我尝试用谷歌搜索错误,但没有找到任何结果。您在服务器和客户端上使用的socket.io版本是什么?socket io的版本是4.0.1