From 346b4d7aa1eb01e9f247a882ef7c049927373492 Mon Sep 17 00:00:00 2001 From: dbrugne Date: Wed, 6 May 2015 19:11:16 +0200 Subject: [PATCH] Make .disconnect() call asynchronous to allow client to receive error message. --- lib/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 24bb212..d3198b7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,6 @@ function noQsMethod(options) { } var auth_timeout = setTimeout(function () { - socket.emit('error', new UnauthorizedError('request_expiration', 'Token wasn\'t received on time')); socket.disconnect('unauthorized'); }, options.timeout || 5000); @@ -23,8 +22,10 @@ function noQsMethod(options) { clearTimeout(auth_timeout); jwt.verify(data.token, options.secret, options, function(err, decoded) { if (err) { - socket.emit('error', new UnauthorizedError('invalid_token', err)); - return socket.disconnect('unauthorized'); + socket.emit('unauthorized', err, function() { + socket.disconnect('unauthorized'); + }); + return; // stop logic, socket will be close on next tick } socket.decoded_token = decoded;