2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-07-21 09:38:31 +02:00

Send 'error' event with error details in case of not received or invalid token.

This commit is contained in:
dbrugne 2015-05-06 17:56:12 +02:00
parent 92663f95b7
commit b053356c5e

View File

@ -15,6 +15,7 @@ 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);
@ -22,6 +23,7 @@ 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');
}