SocketCluster / SocketCluster/socketcluster-client
waitForAuth does not wait
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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