2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-11-09 22:20:08 +01:00

Make .disconnect() call asynchronous to allow client to receive error message.

This commit is contained in:
dbrugne 2015-05-06 19:11:16 +02:00
parent b053356c5e
commit 346b4d7aa1

View File

@ -15,7 +15,6 @@ function noQsMethod(options) {
} }
var auth_timeout = setTimeout(function () { var auth_timeout = setTimeout(function () {
socket.emit('error', new UnauthorizedError('request_expiration', 'Token wasn\'t received on time'));
socket.disconnect('unauthorized'); socket.disconnect('unauthorized');
}, options.timeout || 5000); }, options.timeout || 5000);
@ -23,8 +22,10 @@ function noQsMethod(options) {
clearTimeout(auth_timeout); clearTimeout(auth_timeout);
jwt.verify(data.token, options.secret, options, function(err, decoded) { jwt.verify(data.token, options.secret, options, function(err, decoded) {
if (err) { if (err) {
socket.emit('error', new UnauthorizedError('invalid_token', err)); socket.emit('unauthorized', err, function() {
return socket.disconnect('unauthorized'); socket.disconnect('unauthorized');
});
return; // stop logic, socket will be close on next tick
} }
socket.decoded_token = decoded; socket.decoded_token = decoded;