mirror of
https://github.com/Thream/socketio-jwt.git
synced 2024-07-21 09:38:31 +02:00
'unauthorized' event handler
The example doesn't give any notification on an Unauthorised error. It would be nice to log something on the server too, but I don't see how to do this.
This commit is contained in:
parent
8ebeaba025
commit
3c30d30368
@ -46,8 +46,12 @@ block content
|
||||
|
||||
function openChat() {
|
||||
var socket = io();
|
||||
socket.on('connect', function () {
|
||||
socket.on('authenticated', function () {
|
||||
socket
|
||||
.on('connect', function (msg) {
|
||||
console.log("connected");
|
||||
socket.emit('authenticate', {token: userToken}); // send the jwt
|
||||
})
|
||||
.on('authenticated', function () {
|
||||
//Do
|
||||
$('#login').hide();
|
||||
$('#chat').show();
|
||||
@ -56,10 +60,13 @@ block content
|
||||
$('#m').val('');
|
||||
return false;
|
||||
});
|
||||
socket.on('chat message', function (msg) {
|
||||
})
|
||||
.on('unauthorized', function(msg){
|
||||
console.log("unauthorized: " + JSON.stringify(msg.data));
|
||||
throw new Error(msg.data.type);
|
||||
})
|
||||
.on('chat message', function (msg) {
|
||||
console.log("msg");
|
||||
$('#messages').append($('<li>').text(msg));
|
||||
});
|
||||
}).emit('authenticate', {token: userToken}); // send the jwt
|
||||
})
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user