SocketCluster / SocketCluster/socketcluster-client

waitForAuth does not wait

Open
#121 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
300
Forks
90
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the client-side waitForAuth subscription path and the authentication flow described in the linked authentication documentation. Check the ordering between socket.emit('auth'), MIDDLEWARE_PUBLISH_IN, and subscription handling, especially when authToken is still null. Done means {waitForAuth: true} reliably delays subscription authorization until authentication completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.