From eba9925f2abcf2803e2feae1ab16e5c634f04c43 Mon Sep 17 00:00:00 2001 From: kaisle Date: Thu, 27 Sep 2018 10:53:48 +0200 Subject: [PATCH] Add cookie support --- lib/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index bfcb715..9519a95 100644 --- a/lib/index.js +++ b/lib/index.js @@ -35,7 +35,7 @@ function noQsMethod(options) { message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err }); var callback_timeout; - // If callback explicitely set to false, start timeout to disconnect socket + // If callback explicitely set to false, start timeout to disconnect socket if (options.callback === false || typeof options.callback === "number") { if (typeof options.callback === "number") { if (options.callback < 0) { @@ -57,7 +57,9 @@ function noQsMethod(options) { } }; - if(!data || typeof data.token !== "string") { + var token = options.cookie ? socket.request.cookies[options.cookie] : (data ? data.token : undefined); + + if(!token || typeof token !== "string") { return onError({message: 'invalid token datatype'}, 'invalid_token'); } @@ -96,10 +98,10 @@ function noQsMethod(options) { return onError(err, 'invalid_secret'); } - jwt.verify(data.token, secret, options, onJwtVerificationReady); + jwt.verify(token, secret, options, onJwtVerificationReady); }; - getSecret(socket.request, options.secret, data.token, onSecretReady); + getSecret(socket.request, options.secret, token, onSecretReady); }); }; }