onAuth async Error (SOLVED)

Since I upgraded to 0.9.1 and I changed the verifyClient function to onAuth function, sometimes I need to try to connect to the server several times before I succeed.

The client-side error is:
Firefox can not establish a connection to the server at ws: // localhost: 8080 / BJlPioxfjG? Colyseusid = H1F7jl-9M & channel = sah & tocken = JbFDLDmpKLzx1LWxdTQNqdp09B8BmNc6maz0CGIOYPo3Ltnp1p + ojmOdpM6dwhB5 & requestId = 1. colyseus.js: 1: 31 251 Possible causes: room's onAuth () failed or maxClients has been reached.

maxClients I did not initialize it.

With verifyClient function it works perfect.

Code:

async onAuth (options) {

        let authInst = new Auth();

        if (undefined != options.tocken && !_.isEmpty(options.tocken)) {
            const response = await authInst.checkLogin(options.tocken, this.roomName);
            if (!_.isEmpty(response) && !_.isEmpty(response[0]) && !_.isEmpty(response[0].username)) {
                debug.infoRoomChat("onAuth: ok, tocken %O", options);
                return true;
            } else {
                debug.errorRoomChat("onAuth: invalid tocken %O", options);
                return false;
            }
        } else {
            debug.errorRoomChat("onAuth: undefined tocken %O", options);
        }
        return false;
    }

Thanks.

Hi @rscata,

Are you sure your onAuth is not returning false?

Can you confirm which version of Node.js are you using? We just discovered version 6 is not supported anymore.

Cheers

Hi @endel

I put some console.log for debug.

async onAuth (options) {

        console.log(1);

        let authInst = new Auth();

        if (undefined != options.tocken && !_.isEmpty(options.tocken)) {
            console.log(2);
            const response = await authInst.checkLogin(options.tocken, this.roomName);
            if (!_.isEmpty(response) && !_.isEmpty(response[0]) && !_.isEmpty(response[0].username)) {
                console.log(3);           
                return true;
            } else {
                console.log(4);
                return false;
            }
        } else {
            console.log(5);
            debug.errorRoomChat("onAuth: undefined tocken %O", options);
        }
        console.log(6);
        return false;
    }

When it works well, the output is 1,2 and 3 , and when it does not work ok, the output is 1 and 2.
With the same user I tried, I just refreshed the page and sometimes work and sometimes not.

checkLogin(tocken:string, roomName:string) {
// some validations

return new Promise((resolve, reject) => {
   // db query 

  // if ok 
  return resolve(result)

 // if err
  return reject(err)
}
}

With verifyClient function it works perfect.

I use v9.9.0 node version

I found the problem. The problem was from me when I encode the token.

Sorry, and thank you

@rscata alright! One thing that is not intuitive in this version is that you can only see the error messages and stack traces if you turn on DEBUG=colyseus:errors

DEBUG=colyseus:errors npm start