Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from HotelDon/development
Browse files Browse the repository at this point in the history
timeout now supports value of "none", allowing one to disable the aut…
  • Loading branch information
facundoolano committed Oct 16, 2015
2 parents d825122 + 5830015 commit de4f618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function postAuthenticate(socket, data) {
}
```
* `timeout`: The amount of millisenconds to wait for a client to authenticate before disconnecting it. Defaults to 1000.
* `timeout`: The amount of millisenconds to wait for a client to authenticate before disconnecting it. Defaults to 1000. The value 'none' disables the timeout feature.
## Auth error messages
Expand Down
18 changes: 10 additions & 8 deletions lib/socketio-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var debug = require('debug')('socketio-auth');
* @param {Function} config.authenticate - indicates if authentication was successfull
* @param {Function} config.postAuthenticate=noop - called after the client is authenticated
* @param {Number} [config.timeout=1000] - amount of millisenconds to wait for a client to
* authenticate before disconnecting it
* authenticate before disconnecting it. A value of 'none' means no connection timeout.
*/
module.exports = function socketIOAuth(io, config) {
config = config || {};
Expand Down Expand Up @@ -53,13 +53,15 @@ module.exports = function socketIOAuth(io, config) {

});

setTimeout(function() {
// If the socket didn't authenticate after connection, disconnect it
if (!socket.auth) {
debug('Disconnecting socket %s', socket.id);
socket.disconnect('unauthorized');
}
}, timeout);
if (timeout !== 'none') {
setTimeout(function() {
// If the socket didn't authenticate after connection, disconnect it
if (!socket.auth) {
debug('Disconnecting socket %s', socket.id);
socket.disconnect('unauthorized');
}
}, timeout);
}

});
};
Expand Down

0 comments on commit de4f618

Please sign in to comment.