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 sio.sockets
.on('connection', function (socket) { .on('connection', function (socket) {
console.log(socket.handshake.decoded_token.email, 'connected');
socket.on('ping', function (m) { socket.on('ping', function (m) {
socket.emit('pong', m); socket.emit('pong', m);
}); });

View File

@ -17,7 +17,7 @@ function noQsMethod(options) {
return socket.disconnect('unauthorized'); return socket.disconnect('unauthorized');
} }
socket.user = decoded; socket.decoded_token = decoded;
socket.emit('authenticated'); socket.emit('authenticated');
server.$emit('authenticated', socket); server.$emit('authenticated', socket);
}); });
@ -80,24 +80,11 @@ function authorize(options, onConnection) {
return auth.fail(error, data, accept); return auth.fail(error, data, accept);
} }
data.user = decoded; data.decoded_token = decoded;
data.logged_in = true;
auth.success(data, accept); 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.authorize = authorize;
exports.filterSocketsByUser = filterSocketsByUser;