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:
parent
e62618837c
commit
54a33c260c
@ -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);
|
||||
});
|
||||
|
17
lib/index.js
17
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;
|
||||
|
Loading…
Reference in New Issue
Block a user