Skip to content

Commit

Permalink
Get rid of lodash & crypto-js dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Przytuła committed Feb 1, 2018
1 parent e8037c9 commit 3bb39a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
5 changes: 0 additions & 5 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,3 @@ Package.onTest((api) => {
api.use('practicalmeteor:chai');
api.mainModule('test/server/index.js', 'server');
});

Npm.depends({
'crypto-js': '3.1.9-1',
lodash: '4.17.4'
});
21 changes: 11 additions & 10 deletions server/authenticator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import _ from 'lodash';
import Crypto from 'crypto-js';
import Base64 from 'crypto-js/enc-base64';
import Crypto from 'crypto';

/**
* Gives tools to perform custom authentication.
Expand All @@ -22,8 +20,9 @@ class Authenticator {
* @return {string} hashedToken
*/
static hashToken(token) {
const hashedToken = Crypto.SHA256(token);
return Base64.stringify(hashedToken);
const hash = Crypto.createHash('sha256');
hash.update(token);
return hash.digest('base64');
}

/**
Expand Down Expand Up @@ -74,14 +73,16 @@ class Authenticator {
shouldResumeBeAccepted() {
const loginTokens = this.getUsersLoginTokens();
const hashedToken = this.getTokenFromAttempt();
const userResume = _.find(loginTokens, item => item.hashedToken === hashedToken);
const userResume = loginTokens.find(
item => item.hashedToken === hashedToken
);
if (!userResume) {
return false;
}

const loggedAtLeastOnce = _.some(this.loginAttempt.methodArguments, {
loggedAtLeastOnce: true
});
const methodArguments = this.loginAttempt.methodArguments || [];
const loggedAtLeastOnce = methodArguments.some(
argument => argument.loggedAtLeastOnce === true
);
return (userResume.rememberMe || loggedAtLeastOnce);
}

Expand Down

0 comments on commit 3bb39a9

Please sign in to comment.