From 7cc9d0594d35a542151770a8160c2f08b8e9680b Mon Sep 17 00:00:00 2001 From: jkaplon Date: Sat, 22 Apr 2017 09:26:21 -0400 Subject: [PATCH] Add trt/catch for session verification to avoid crashing errors, seems to be working well now. --- server.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 4c9dd23..ebad0f9 100644 --- a/server.js +++ b/server.js @@ -101,16 +101,17 @@ io.use(iosess(session)); io.on('connection', function(socket){ //winston.info('a user connected'); winston.info('session id, '+ socket.handshake.session.id); - if (!socket.handshake.session.passport.user) { + // next line no worky...but i can get by with only user-#. + //winston.info('user name, '+ socket.handshake.session.passport.user.username); + try { + var userNum = socket.handshake.session.passport.user; + } catch (ex) { // Send redirect to client, socket connection will close when client goes back to /login. // But disconnect just in case client is misbehaving. winston.info('Session DNE, redirect and disconnect.'); socket.emit('redirect', '/login'); socket.disconnect(); } - // next line no worky...but might get by with only user-#. - //winston.info('user name, '+ socket.handshake.session.passport.user.username); - var userNum = socket.handshake.session.passport.user; winston.info('user id, '+ userNum); socket.join(userNum); var notePath, noteDir