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

change user to decoded_token

This commit is contained in:
José F. Romaniello 2014-01-14 17:44:03 -03:00
parent e62618837c
commit 54a33c260c
2 changed files with 3 additions and 15 deletions

View File

@ -38,6 +38,7 @@ sio.set('authorization', socketio_jwt.authorize({
sio.sockets
.on('connection', function (socket) {
console.log(socket.handshake.decoded_token.email, 'connected');
socket.on('ping', function (m) {
socket.emit('pong', m);
});

View File

@ -17,7 +17,7 @@ function noQsMethod(options) {
return socket.disconnect('unauthorized');
}
socket.user = decoded;
socket.decoded_token = decoded;
socket.emit('authenticated');
server.$emit('authenticated', socket);
});
@ -80,24 +80,11 @@ function authorize(options, onConnection) {
return auth.fail(error, data, accept);
}
data.user = decoded;
data.logged_in = true;
data.decoded_token = decoded;
auth.success(data, accept);
});
};
}
function filterSocketsByUser(socketIo, filter){
var handshaken = socketIo.sockets.manager.handshaken;
return Object.keys(handshaken || {})
.filter(function(skey){
return filter(handshaken[skey].user);
})
.map(function(skey){
return socketIo.sockets.manager.sockets.sockets[skey];
});
}
exports.authorize = authorize;
exports.filterSocketsByUser = filterSocketsByUser;