Commit 8308b642 authored by Killian Kemps's avatar Killian Kemps
Browse files

Force page reload from socket when user not identified

parent 9c70457b
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
$('#m').val(''); $('#m').val('');
return false; return false;
}); });
socket.on('reload page', function(){
document.location.reload(true);
});
socket.on('chat message', function(msg){ socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg)); $('#messages').append($('<li>').text(msg));
......
...@@ -107,7 +107,14 @@ function getAppstateName(email) { ...@@ -107,7 +107,14 @@ function getAppstateName(email) {
io.on('connection', function(socket){ io.on('connection', function(socket){
var cookieArray = socket.request.headers.cookie.split('='); var cookieArray = socket.request.headers.cookie.split('=');
var email = sessions.util.decode(cookieOptions, cookieArray[ cookieArray.length - 1 ]).content.email; var cookie = sessions.util.decode(cookieOptions, cookieArray[ cookieArray.length - 1 ]);
if (cookie === undefined) {
console.log('Sending reload event');
socket.emit('reload page');
}
var email = cookie.content.email;
console.log('Socket email: ', email); console.log('Socket email: ', email);
var currentUser = users[email]; var currentUser = users[email];
...@@ -159,6 +166,10 @@ io.on('connection', function(socket){ ...@@ -159,6 +166,10 @@ io.on('connection', function(socket){
} }
).catch(function(err) { ).catch(function(err) {
console.log('An error occured: ', err); console.log('An error occured: ', err);
if (err === 'currentUser is undefined') {
console.log('Sending reload event');
socket.emit('reload page');
}
}); });
socket.on('chat message', function(msg){ socket.on('chat message', function(msg){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment