diff --git a/example/server.js b/example/server.js index 9a694d0..fd3886e 100644 --- a/example/server.js +++ b/example/server.js @@ -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); }); diff --git a/lib/index.js b/lib/index.js index 52f52cd..2a7c425 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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;