whitespace
This commit is contained in:
parent
27aaab3161
commit
211f3af592
50
lib/index.js
50
lib/index.js
@ -29,32 +29,32 @@ function noQsMethod(options) {
|
|||||||
}
|
}
|
||||||
// error handler
|
// error handler
|
||||||
var onError = function(err, code) {
|
var onError = function(err, code) {
|
||||||
if (err) {
|
if (err) {
|
||||||
code = code || 'unknown';
|
code = code || 'unknown';
|
||||||
var error = new UnauthorizedError(code, {
|
var error = new UnauthorizedError(code, {
|
||||||
message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err
|
message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err
|
||||||
});
|
});
|
||||||
var callback_timeout;
|
var callback_timeout;
|
||||||
// If callback explicitely set to false, start timeout to disconnect socket
|
// If callback explicitely set to false, start timeout to disconnect socket
|
||||||
if (options.callback === false || typeof options.callback === "number") {
|
if (options.callback === false || typeof options.callback === 'number') {
|
||||||
if (typeof options.callback === "number") {
|
if (typeof options.callback === 'number') {
|
||||||
if (options.callback < 0) {
|
if (options.callback < 0) {
|
||||||
// If callback is negative(invalid value), make it positive
|
// If callback is negative(invalid value), make it positive
|
||||||
options.callback = Math.abs(options.callback);
|
options.callback = Math.abs(options.callback);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
callback_timeout = setTimeout(function () {
|
|
||||||
socket.disconnect('unauthorized');
|
|
||||||
}, (options.callback === false ? 0 : options.callback));
|
|
||||||
}
|
}
|
||||||
socket.emit('unauthorized', error, function() {
|
callback_timeout = setTimeout(function () {
|
||||||
if (typeof options.callback === "number") {
|
|
||||||
clearTimeout(callback_timeout);
|
|
||||||
}
|
|
||||||
socket.disconnect('unauthorized');
|
socket.disconnect('unauthorized');
|
||||||
});
|
}, (options.callback === false ? 0 : options.callback));
|
||||||
return; // stop logic, socket will be close on next tick
|
|
||||||
}
|
}
|
||||||
|
socket.emit('unauthorized', error, function() {
|
||||||
|
if (typeof options.callback === 'number') {
|
||||||
|
clearTimeout(callback_timeout);
|
||||||
|
}
|
||||||
|
socket.disconnect('unauthorized');
|
||||||
|
});
|
||||||
|
return; // stop logic, socket will be close on next tick
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var token = options.cookie ? socket.request.cookies[options.cookie] : (data ? data.token : undefined);
|
var token = options.cookie ? socket.request.cookies[options.cookie] : (data ? data.token : undefined);
|
||||||
@ -81,8 +81,8 @@ function noQsMethod(options) {
|
|||||||
} else {
|
} else {
|
||||||
//try getting the current namespace otherwise fallback to all sockets.
|
//try getting the current namespace otherwise fallback to all sockets.
|
||||||
var namespace = (server.nsps && socket.nsp &&
|
var namespace = (server.nsps && socket.nsp &&
|
||||||
server.nsps[socket.nsp.name]) ||
|
server.nsps[socket.nsp.name]) ||
|
||||||
server.sockets;
|
server.sockets;
|
||||||
|
|
||||||
// explicit namespace
|
// explicit namespace
|
||||||
namespace.emit('authenticated', socket);
|
namespace.emit('authenticated', socket);
|
||||||
@ -237,7 +237,7 @@ function getSecret(request, secret, token, callback) {
|
|||||||
} else {
|
} else {
|
||||||
callback(null, secret);
|
callback(null, secret);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.authorize = authorize;
|
exports.authorize = authorize;
|
||||||
exports.UnauthorizedError = UnauthorizedError;
|
exports.UnauthorizedError = UnauthorizedError;
|
||||||
|
Reference in New Issue
Block a user