2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-11-09 22:20:08 +01:00

Merge branch 'jghaines-master'

This commit is contained in:
José F. Romaniello 2016-06-21 09:41:31 -03:00
commit e78e376480
2 changed files with 19 additions and 10 deletions

View File

@ -11,6 +11,7 @@ var env = {
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID, AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_DOMAIN: process.env.AUTH0_DOMAIN AUTH0_DOMAIN: process.env.AUTH0_DOMAIN
}; };
var port = process.env.PORT || 3001;
app.set('views', __dirname + '/views'); app.set('views', __dirname + '/views');
app.set('view engine', 'pug'); app.set('view engine', 'pug');
@ -34,6 +35,7 @@ app.get('/', function (req, res) {
res.render('index', { env: env }); res.render('index', { env: env });
}); });
http.listen(3001, function(){ http.listen(port, function(){
console.log('listening on *:3001'); console.log('listening on *:' + port);
}); });

View File

@ -46,8 +46,12 @@ block content
function openChat() { function openChat() {
var socket = io(); var socket = io();
socket.on('connect', function () { socket
socket.on('authenticated', function () { .on('connect', function (msg) {
console.log("connected");
socket.emit('authenticate', {token: userToken}); // send the jwt
})
.on('authenticated', function () {
//Do //Do
$('#login').hide(); $('#login').hide();
$('#chat').show(); $('#chat').show();
@ -56,10 +60,13 @@ block content
$('#m').val(''); $('#m').val('');
return false; return false;
}); });
socket.on('chat message', function (msg) { })
console.log("msg"); .on('unauthorized', function(msg){
$('#messages').append($('<li>').text(msg)); console.log("unauthorized: " + JSON.stringify(msg.data));
}); throw new Error(msg.data.type);
}).emit('authenticate', {token: userToken}); // send the jwt })
}) .on('chat message', function (msg) {
console.log("msg");
$('#messages').append($('<li>').text(msg));
});
}; };