Skip to content

waitForAuth does not wait #121

Open
Open
@murat-mehmet

Description

@murat-mehmet

I'm trying to auth a user and then subscribe a channel using {waitForAuth: true}. Here is the client code:

var socket = socketCluster.create(options);
  socket.emit('auth', 'test');
  var channel = socket.subscribe('my-channel', {waitForAuth: true});
  channel.watch((e) => {
    console.log(JSON.stringify(e));
  })

And the server code is as described in https://socketcluster.io/#!/docs/authentication

The problem is that the MIDDLEWARE_PUBLISH_IN always runs before auth because of the db code and the user fails to subscribe; authToken is always null.

It works when I change to

socket.emit('auth', 'test', function (err) {
  if (!err) {
    var channel = socket.subscribe('my-channel');
    channel.watch((e) => {
      console.log(JSON.stringify(e));
    });
  }
});

which is quite spaghetti.
So the problem is that waitForAuth is not actually waiting anything. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions