Cannot read property 'indexOf' socketiojwt

Viewed 433

I tried to add socketio-jwt module into my app project in order to check for authentication. I tried entering the minimum default code they have on their docs site. i run the app with no errors but when i browse to the url i get error on cmd prompt

TypeError: Cannot read property 'indexOf' of undefined at Namespace. (C:\Users\anjelotti\Desktop\chat.io\node_modules\so cketio-jwt\lib\index.js:16:30)

The code on the server.js

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);
            });
});

and the code sitting on the 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);
    })
});

I tried googling for the error but it didn't get me anywhere.

1 Answers
Related