Skip to content

Commit

Permalink
Merge pull request #7 from tprzytula/development
Browse files Browse the repository at this point in the history
Fix for #6 & Use callLoginMethod from provided AccountsClient instance
  • Loading branch information
tprzytula committed May 10, 2018
2 parents 693b53f + 188ea3d commit 8747d41
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ Gives the possibility to set a custom accounts instance to be used for the login

## Testing

You can test this dependency by running `npm run test`
You can test this dependency by running `npm run test` or check the recent results from circleci & travis-ci
45 changes: 25 additions & 20 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ class RememberMe {
* @returns {function} loginWithPassword
* @private
*/
getLoginWithPasswordMethod() {
return this.remoteConnection
? this.remoteConnection.loginWithPassword
: Meteor.loginWithPassword;
}
getLoginWithPasswordMethod = () => {
if (this.remoteConnection) {
return this.remoteConnection.loginWithPassword;
}

return Meteor.loginWithPassword;
};

/**
* Returns call method either from the main
* connection or remote one if set.
* @returns {function} call
* @private
*/
getCallMethod() {
return this.remoteConnection
? this.remoteConnection.call.bind(this.remoteConnection)
: Meteor.call;
}
getCallMethod = () => {
if (this.remoteConnection) {
return this.remoteConnection.call.bind(this.remoteConnection);
}

return Meteor.call;
};

/**
* Wrapper for the Meteor.loginWithPassword
Expand All @@ -57,7 +61,7 @@ class RememberMe {
* update the rememberMe flag on the server side.
* @public
*/
loginWithPassword(...params) {
loginWithPassword = (...params) => {
const [user, password, ...rest] = params;
const flag = exportFlagFromParams(rest);
const callbackMethod = exportCallbackFromParams(rest);
Expand All @@ -68,15 +72,15 @@ class RememberMe {
}
callbackMethod(error);
});
}
};

/**
* Sends request to the server to update
* the remember me setting.
* @param {boolean} flag
* @private
*/
updateFlag(flag) {
updateFlag = (flag) => {
const callMethod = this.getCallMethod();
callMethod(this.methodName, flag, (error) => {
if (error && error.error === 404) {
Expand All @@ -94,7 +98,7 @@ class RememberMe {
);
}
});
}
};

/**
* Switches from using the current login system to
Expand All @@ -104,26 +108,27 @@ class RememberMe {
* @returns {boolean} result
* @public
*/
changeAccountsSystem(customAccounts) {
changeAccountsSystem = (customAccounts) => {
if (customAccounts instanceof AccountsClient &&
customAccounts.connection) {
this.remoteConnection = customAccounts.connection;
this.setLoginMethod();
this.setLoginMethod(customAccounts);
overrideAccountsLogin(customAccounts);
return true;
}
console.error('meteor/tprzytula:remember-me' +
'\nProvided parameter is not a valid AccountsClient.');
return false;
}
};

/**
* Since freshly created AccountsClients are not having
* this method by default it's required to make sure that
* the set accounts system will contain it.
* @param {AccountsClient} accountsInstance
* @private
*/
setLoginMethod() {
setLoginMethod = (accountsInstance) => {
if ('loginWithPassword' in this.remoteConnection) {
// Login method is already present
return;
Expand All @@ -140,7 +145,7 @@ class RememberMe {
? { username: selector }
: { email: selector };
}
Meteor.remoteUsers.callLoginMethod({
accountsInstance.callLoginMethod({
methodArguments: [{
user: selector,
password: Accounts._hashPassword(password)
Expand All @@ -162,7 +167,7 @@ class RememberMe {
});
};
/* eslint-enable */
}
};
}

export default new RememberMe();
Expand Down
4 changes: 4 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.2.1] - 10.05.2018
* Change client methods to arrow functions to prevent wrong context issues ([Issue #6](https://github.com/tprzytula/Meteor-Remember-Me/issues/6))
* loginWithPassword method for custom accounts was throwing an error if accounts were not stored in `Meteor.remoteUsers` (whoops!)

## [0.2.0] - 13.03.2018
New feature:
* Add support for custom AccountsClient ([introduction](CUSTOM_ACCOUNTS.md))
Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'tprzytula:remember-me',
version: '0.2.0',
version: '0.2.1',
summary: 'Extension for Meteor account-base package with the implementation of rememberMe',
git: 'https://github.com/tprzytulacc/Meteor-RememberMe',
documentation: 'doc/README.md'
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rememberMe",
"version": "0.2.0",
"version": "0.2.1",
"description": "Extension for Meteor account-base package with the implementation of rememberMe",
"license": "MIT",
"author": "Tomasz Przytuła <[email protected]>",
Expand All @@ -19,9 +19,11 @@
"eslint": "eslint ./client ./server ./test || true",
"eslint-check": "eslint ./client ./server ./test",
"eslint-fix": "eslint ./client ./server ./test --fix || true",
"test": "cross-env TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package meteortesting:mocha"
"test": "cross-env TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package meteortesting:mocha",
"test-watch": "cross-env WATCH=1 TEST_BROWSER_DRIVER=chrome meteor test --driver-package meteortesting:mocha"
},
"devDependencies": {
"@babel/runtime": "^7.0.0-beta.44",
"babel-eslint": "^8.2.2",
"bcrypt": "^2.0.0",
"chromedriver": "^2.37.0",
Expand All @@ -37,9 +39,6 @@
"sinon": "^4.5.0",
"ultimate-chai": "^4.1.1"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.44"
},
"pre-commit": [
"eslint-check",
"test"
Expand Down
1 change: 1 addition & 0 deletions test/server/utils/testUser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { Accounts } = require('meteor/accounts-base');
const Authenticator = require('./../../../server/authenticator').default;

/**
Expand Down

0 comments on commit 8747d41

Please sign in to comment.