From 674bbb659aa1e84bdefa12b53aef6ad724e74a60 Mon Sep 17 00:00:00 2001 From: Bruce Hem Date: Fri, 19 Aug 2016 22:01:36 +0700 Subject: [PATCH] Fix authentication flow on client side --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 033987e..d9b9bc1 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,16 @@ __Client side__: ```javascript var socket = io.connect('http://localhost:9000'); -socket.on('connect', function (socket) { +socket.on('connect', function () { socket + .emit('authenticate', {token: jwt}) //send the jwt .on('authenticated', function () { //do other things }) - .emit('authenticate', {token: jwt}); //send the jwt + .on('unauthorized', function(msg) { + console.log("unauthorized: " + JSON.stringify(msg.data)); + throw new Error(msg.data.type); + }) }); ```