Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookie support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
});
};
}
Expand Down