Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

Commit

Permalink
Add checkAuth() utility function to check if auth object is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t committed Dec 25, 2017
1 parent 17619ca commit 9cc86d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/clients/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ class WebsocketClient extends EventEmitter {
super();
this.productIDs = Utils.determineProductIDs(productIDs);
this.websocketURI = websocketURI;
if (auth && !(auth.secret && auth.key && auth.passphrase)) {
throw new Error(
'Invalid or incomplete authentication credentials. You should either provide all of the secret, key and passphrase fields, or leave auth null'
);
}
this.channels = channels;
this.auth = auth || {};
this.auth = Utils.checkAuth(auth);
this.heartbeat = heartbeat;
this.connect();
}
Expand Down
10 changes: 10 additions & 0 deletions lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ function determineProductIDs(productIDs) {
return [productIDs];
}

function checkAuth(auth) {
if (auth && !(auth.secret && auth.key && auth.passphrase)) {
throw new Error(
'Invalid or incomplete authentication credentials. You should either provide all of the secret, key and passphrase fields, or leave auth null'
);
}
return auth || {};
}

module.exports = {
determineProductIDs,
checkAuth,
};

0 comments on commit 9cc86d1

Please sign in to comment.