From 2e0f5b74db8368c0ec945f7a897383f25280ba88 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 28 Oct 2016 15:40:03 +0100 Subject: [PATCH] send connectionAccepted/Rejected events on connect let the client know whether it has successfully authenticated --- services/real-time/app/coffee/Router.coffee | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index 2f56020578..2cc655eafc 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -39,11 +39,22 @@ module.exports = Router = app.post "/drain", httpAuth, HttpApiController.startDrain session.on 'connection', (error, client, session) -> + if client? and error?.message?.match(/could not look up session by key/) + logger.err err: error, client: client?, session: session?, "invalid session" + # tell the client to reauthenticate if it has an invalid session key + client.emit("connectionRejected", {message: "invalid session"}) + client.disconnect() + return + if error? - logger.err err: error, "error when client connected" + logger.err err: error, client: client?, session: session?, "error when client connected" + client?.emit("connectionRejected", {message: "error"}) client?.disconnect() return + # send positive confirmation that the client has a valid connection + client.emit("connectionAccepted") + metrics.inc('socket-io.connection') logger.log session: session, client_id: client.id, "client connected"