Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/client

Package Overview
Dependencies
Maintainers
5
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/client - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10-alpha.11535f01

flow-typed/npm/crypto-js_vx.x.x.js

255

lib-es6/AccountsClient.js

@@ -32,2 +32,4 @@ 'use strict';

var _encryption = require('./encryption');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -57,3 +59,3 @@

this.options = options;
this.storage = options.tokenStorage;
this.storage = options.tokenStorage || _config3.default.tokenStorage;
if (!transport) {

@@ -67,4 +69,5 @@ throw new _common.AccountsError('A REST or GraphQL transport is required');

var reduxStoreKey = options.reduxStoreKey || _config3.default.reduxStoreKey;
this.store = options.store || (0, _createStore2.default)({
reducers: _defineProperty({}, options.reduxStoreKey, _module2.default),
reducers: _defineProperty({}, reduxStoreKey, _module2.default),
middleware: middleware

@@ -158,11 +161,6 @@ });

}, {
key: 'user',
value: function user() {
var user = this.getState().get('user');
return user ? user.toJS() : null;
}
}, {
key: 'tokens',
key: 'loadTokensFromStorage',
value: function () {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var tokens;
return regeneratorRuntime.wrap(function _callee4$(_context4) {

@@ -182,8 +180,10 @@ while (1) {

_context4.t1 = _context4.sent;
return _context4.abrupt('return', {
tokens = {
accessToken: _context4.t0,
refreshToken: _context4.t1
});
};
case 7:
this.store.dispatch((0, _module.setTokens)(tokens));
case 8:
case 'end':

@@ -196,9 +196,26 @@ return _context4.stop();

function tokens() {
function loadTokensFromStorage() {
return _ref4.apply(this, arguments);
}
return tokens;
return loadTokensFromStorage;
}()
}, {
key: 'user',
value: function user() {
var user = this.getState().get('user');
return user ? user.toJS() : null;
}
}, {
key: 'tokens',
value: function tokens() {
var tokens = this.getState().get('tokens');
return tokens ? tokens.toJS() : {
accessToken: null,
refreshToken: null
};
}
}, {
key: 'clearTokens',

@@ -307,3 +324,3 @@ value: function () {

if (!(accessToken && refreshToken)) {
_context7.next = 30;
_context7.next = 33;
break;

@@ -313,2 +330,4 @@ }

_context7.prev = 6;
this.store.dispatch((0, _module.loggingIn)(true));
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken);

@@ -319,3 +338,3 @@ currentTime = Date.now() / 1000;

if (!(decodedRefreshToken.exp < currentTime)) {
_context7.next = 14;
_context7.next = 15;
break;

@@ -326,26 +345,30 @@ }

this.clearUser();
_context7.next = 21;
_context7.next = 23;
break;
case 14:
_context7.next = 16;
case 15:
_context7.next = 17;
return this.transport.refreshTokens(accessToken, refreshToken);
case 16:
case 17:
refreshedSession = _context7.sent;
_context7.next = 19;
this.store.dispatch((0, _module.loggingIn)(false));
_context7.next = 21;
return this.storeTokens(refreshedSession);
case 19:
case 21:
this.store.dispatch((0, _module.setTokens)(refreshedSession.tokens));
this.store.dispatch((0, _module.setUser)(refreshedSession.user));
case 21:
_context7.next = 28;
case 23:
_context7.next = 31;
break;
case 23:
_context7.prev = 23;
case 25:
_context7.prev = 25;
_context7.t0 = _context7['catch'](6);
this.store.dispatch((0, _module.loggingIn)(false));
this.clearTokens();

@@ -355,7 +378,7 @@ this.clearUser();

case 28:
_context7.next = 33;
case 31:
_context7.next = 36;
break;
case 30:
case 33:
this.clearTokens();

@@ -365,3 +388,3 @@ this.clearUser();

case 33:
case 36:
case 'end':

@@ -371,3 +394,3 @@ return _context7.stop();

}
}, _callee7, this, [[6, 23]]);
}, _callee7, this, [[6, 25]]);
}));

@@ -385,3 +408,3 @@

var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8(user, callback) {
var userId;
var hashAlgorithm, password, userToCreate, userId;
return regeneratorRuntime.wrap(function _callee8$(_context8) {

@@ -402,3 +425,3 @@ while (1) {

case 2:
if (_common.validators.validatePassword(user.password)) {
if (!(!user.password || (0, _lodash.isString)(user.password) && !_common.validators.validatePassword(user.password))) {
_context8.next = 4;

@@ -419,7 +442,10 @@ break;

case 6:
_context8.prev = 6;
_context8.next = 9;
return this.transport.createUser(user);
hashAlgorithm = this.options.passwordHashAlgorithm;
password = user.password && hashAlgorithm ? (0, _encryption.hashPassword)(user.password, hashAlgorithm) : user.password;
userToCreate = _extends({}, user, { password: password });
_context8.prev = 9;
_context8.next = 12;
return this.transport.createUser(userToCreate);
case 9:
case 12:
userId = _context8.sent;

@@ -430,12 +456,13 @@

}
_context8.next = 13;
_context8.next = 16;
return this.loginWithPassword({ id: userId }, user.password);
case 13:
_context8.next = 19;
case 16:
_context8.next = 22;
break;
case 15:
_context8.prev = 15;
_context8.t0 = _context8['catch'](6);
case 18:
_context8.prev = 18;
_context8.t0 = _context8['catch'](9);

@@ -447,3 +474,3 @@ if (callback && (0, _lodash.isFunction)(callback)) {

case 19:
case 22:
case 'end':

@@ -453,3 +480,3 @@ return _context8.stop();

}
}, _callee8, this, [[6, 15]]);
}, _callee8, this, [[9, 18]]);
}));

@@ -467,3 +494,3 @@

var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(user, password, callback) {
var res;
var hashAlgorithm, pass, res;
return regeneratorRuntime.wrap(function _callee9$(_context9) {

@@ -492,16 +519,23 @@ while (1) {

_context9.prev = 5;
_context9.next = 8;
return this.transport.loginWithPassword(user, password);
hashAlgorithm = this.options.passwordHashAlgorithm;
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password;
_context9.next = 10;
return this.transport.loginWithPassword(user, pass);
case 8:
case 10:
res = _context9.sent;
this.store.dispatch((0, _module.loggingIn)(false));
_context9.next = 12;
_context9.next = 14;
return this.storeTokens(res);
case 12:
case 14:
this.store.dispatch((0, _module.setTokens)(res.tokens));
this.store.dispatch((0, _module.setUser)(res.user));
this.options.onSignedInHook();
if (this.options.onSignedInHook && (0, _lodash.isFunction)(this.options.onSignedInHook)) {
this.options.onSignedInHook();
}
if (callback && (0, _lodash.isFunction)(callback)) {

@@ -513,4 +547,4 @@ callback(null, res);

case 19:
_context9.prev = 19;
case 21:
_context9.prev = 21;
_context9.t0 = _context9['catch'](5);

@@ -524,3 +558,3 @@

case 24:
case 26:
case 'end':

@@ -530,3 +564,3 @@ return _context9.stop();

}
}, _callee9, this, [[5, 19]]);
}, _callee9, this, [[5, 21]]);
}));

@@ -583,3 +617,6 @@

}
this.options.onSignedOutHook();
if (this.options.onSignedOutHook) {
this.options.onSignedOutHook();
}
_context10.next = 18;

@@ -650,2 +687,3 @@ break;

var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12(token, newPassword) {
var hashAlgorithm, password;
return regeneratorRuntime.wrap(function _callee12$(_context12) {

@@ -655,16 +693,26 @@ while (1) {

case 0:
_context12.prev = 0;
_context12.next = 3;
return this.transport.resetPassword(token, newPassword);
if (_common.validators.validatePassword(newPassword)) {
_context12.next = 2;
break;
}
case 3:
_context12.next = 8;
throw new _common.AccountsError('Password is invalid!');
case 2:
hashAlgorithm = this.options.passwordHashAlgorithm;
password = hashAlgorithm ? (0, _encryption.hashPassword)(newPassword, hashAlgorithm) : newPassword;
_context12.prev = 4;
_context12.next = 7;
return this.transport.resetPassword(token, password);
case 7:
_context12.next = 12;
break;
case 5:
_context12.prev = 5;
_context12.t0 = _context12['catch'](0);
case 9:
_context12.prev = 9;
_context12.t0 = _context12['catch'](4);
throw new _common.AccountsError(_context12.t0.message);
case 8:
case 12:
case 'end':

@@ -674,3 +722,3 @@ return _context12.stop();

}
}, _callee12, this, [[0, 5]]);
}, _callee12, this, [[4, 9]]);
}));

@@ -692,16 +740,24 @@

case 0:
_context13.prev = 0;
_context13.next = 3;
if (_common.validators.validateEmail(email)) {
_context13.next = 2;
break;
}
throw new _common.AccountsError('Valid email must be provided');
case 2:
_context13.prev = 2;
_context13.next = 5;
return this.transport.sendResetPasswordEmail(email);
case 3:
_context13.next = 8;
case 5:
_context13.next = 10;
break;
case 5:
_context13.prev = 5;
_context13.t0 = _context13['catch'](0);
case 7:
_context13.prev = 7;
_context13.t0 = _context13['catch'](2);
throw new _common.AccountsError(_context13.t0.message);
case 8:
case 10:
case 'end':

@@ -711,3 +767,3 @@ return _context13.stop();

}
}, _callee13, this, [[0, 5]]);
}, _callee13, this, [[2, 7]]);
}));

@@ -729,16 +785,24 @@

case 0:
_context14.prev = 0;
_context14.next = 3;
if (_common.validators.validateEmail(email)) {
_context14.next = 2;
break;
}
throw new _common.AccountsError('Valid email must be provided');
case 2:
_context14.prev = 2;
_context14.next = 5;
return this.transport.sendVerificationEmail(email);
case 3:
_context14.next = 8;
case 5:
_context14.next = 10;
break;
case 5:
_context14.prev = 5;
_context14.t0 = _context14['catch'](0);
case 7:
_context14.prev = 7;
_context14.t0 = _context14['catch'](2);
throw new _common.AccountsError(_context14.t0.message);
case 8:
case 10:
case 'end':

@@ -748,3 +812,3 @@ return _context14.stop();

}
}, _callee14, this, [[0, 5]]);
}, _callee14, this, [[2, 7]]);
}));

@@ -767,3 +831,22 @@

config: function config(options, transport) {
this.instance = new AccountsClient(_extends({}, _config3.default, options), transport);
var _this = this;
return _asyncToGenerator(regeneratorRuntime.mark(function _callee15() {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_this.instance = new AccountsClient(_extends({}, _config3.default, options), transport);
return _context15.abrupt('return', _this.instance.loadTokensFromStorage().then(function () {
return _this.instance;
}));
case 2:
case 'end':
return _context15.stop();
}
}
}, _callee15, _this);
}))();
},

@@ -770,0 +853,0 @@ user: function user() {

@@ -7,2 +7,6 @@ 'use strict';

var _crypto = require('crypto');
var _crypto2 = _interopRequireDefault(_crypto);
require('./mockLocalStorage');

@@ -47,14 +51,65 @@

describe('config', function () {
it('requires a transport', function () {
try {
_AccountsClient2.default.config({
history: history
});
throw new Error();
} catch (err) {
var message = err.message;
it('requires a transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var message;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return _AccountsClient2.default.config({
history: history
});
expect(message).toEqual('A REST or GraphQL transport is required');
}
});
case 3:
throw new Error();
case 6:
_context.prev = 6;
_context.t0 = _context['catch'](0);
message = _context.t0.message;
expect(message).toEqual('A REST or GraphQL transport is required');
case 10:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[0, 6]]);
})));
it('should eagerly load tokens from storage after using config', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
var transport, tokens;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
transport = {
loginWithPassword: function loginWithPassword() {
return Promise.resolve(loggedInUser);
}
};
_context2.next = 3;
return _AccountsClient2.default.config({
history: history,
tokenStorage: {
getItem: function getItem() {
return Promise.resolve('testValue');
}
}
}, transport);
case 3:
tokens = _AccountsClient2.default.tokens();
expect(tokens.accessToken).toBeDefined();
expect(tokens.refreshToken).toBeDefined();
case 6:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
})));
it('sets the transport', function () {

@@ -69,7 +124,7 @@ var transport = {};

describe('createUser', function () {
it('requires user object', _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
it('requires user object', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
var message;
return regeneratorRuntime.wrap(function _callee$(_context) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context3.prev = _context3.next) {
case 0:

@@ -81,4 +136,4 @@ _AccountsClient2.default.config({

});
_context.prev = 1;
_context.next = 4;
_context3.prev = 1;
_context3.next = 4;
return _AccountsClient2.default.createUser();

@@ -90,5 +145,5 @@

case 7:
_context.prev = 7;
_context.t0 = _context['catch'](1);
message = _context.t0.message;
_context3.prev = 7;
_context3.t0 = _context3['catch'](1);
message = _context3.t0.message;

@@ -99,14 +154,15 @@ expect(message).toEqual('Unrecognized options for create user request');

case 'end':
return _context.stop();
return _context3.stop();
}
}
}, _callee, undefined, [[1, 7]]);
}, _callee3, undefined, [[1, 7]]);
})));
it('requires password', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
it('requires password', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var message;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context4.prev = _context4.next) {
case 0:
_AccountsClient2.default.config({
_context4.next = 2;
return _AccountsClient2.default.config({
history: history

@@ -116,4 +172,6 @@ }, {

});
_context2.prev = 1;
_context2.next = 4;
case 2:
_context4.prev = 2;
_context4.next = 5;
return _AccountsClient2.default.createUser({

@@ -123,24 +181,24 @@ password: null

case 4:
case 5:
throw new Error();
case 7:
_context2.prev = 7;
_context2.t0 = _context2['catch'](1);
message = _context2.t0.message;
case 8:
_context4.prev = 8;
_context4.t0 = _context4['catch'](2);
message = _context4.t0.message;
expect(message).toEqual('Password is required');
case 11:
case 12:
case 'end':
return _context2.stop();
return _context4.stop();
}
}
}, _callee2, undefined, [[1, 7]]);
}, _callee4, undefined, [[2, 8]]);
})));
it('requires username or an email', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
it('requires username or an email', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
var message;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context5.prev = _context5.next) {
case 0:

@@ -150,4 +208,4 @@ _AccountsClient2.default.config({ history: history }, {

});
_context3.prev = 1;
_context3.next = 4;
_context5.prev = 1;
_context5.next = 4;
return _AccountsClient2.default.createUser({

@@ -163,5 +221,5 @@ password: '123456',

case 7:
_context3.prev = 7;
_context3.t0 = _context3['catch'](1);
message = _context3.t0.message;
_context5.prev = 7;
_context5.t0 = _context5['catch'](1);
message = _context5.t0.message;

@@ -172,12 +230,12 @@ expect(message).toEqual('Username or Email is required');

case 'end':
return _context3.stop();
return _context5.stop();
}
}
}, _callee3, undefined, [[1, 7]]);
}, _callee5, undefined, [[1, 7]]);
})));
it('calls callback on succesfull user creation', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
it('calls callback on succesfull user creation', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() {
var callback, transport;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context6.prev = _context6.next) {
case 0:

@@ -193,5 +251,7 @@ callback = jest.fn();

};
_context6.next = 4;
return _AccountsClient2.default.config({ history: history }, transport);
_AccountsClient2.default.config({ history: history }, transport);
_context4.next = 5;
case 4:
_context6.next = 6;
return _AccountsClient2.default.createUser({

@@ -202,18 +262,18 @@ password: '123456',

case 5:
case 6:
expect(callback.mock.calls.length).toEqual(1);
case 6:
case 7:
case 'end':
return _context4.stop();
return _context6.stop();
}
}
}, _callee4, undefined);
}, _callee6, undefined);
})));
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context7.prev = _context7.next) {
case 0:

@@ -225,9 +285,9 @@ transport = {

};
_context7.next = 3;
return _AccountsClient2.default.config({ history: history }, transport);
_AccountsClient2.default.config({ history: history }, transport);
case 3:
callback = jest.fn();
_context5.prev = 3;
_context5.next = 6;
_context7.prev = 4;
_context7.next = 7;
return _AccountsClient2.default.createUser({

@@ -238,8 +298,8 @@ password: '123456',

case 6:
case 7:
throw new Error();
case 9:
_context5.prev = 9;
_context5.t0 = _context5['catch'](3);
case 10:
_context7.prev = 10;
_context7.t0 = _context7['catch'](4);

@@ -249,14 +309,14 @@ expect(callback.mock.calls.length).toEqual(1);

case 13:
case 14:
case 'end':
return _context5.stop();
return _context7.stop();
}
}
}, _callee5, undefined, [[3, 9]]);
}, _callee7, undefined, [[4, 10]]);
})));
it('calls login function with user id and password of created user', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() {
it('calls login function with user id and password of created user', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() {
var transport;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context8.prev = _context8.next) {
case 0:

@@ -275,3 +335,3 @@ transport = {

_context6.next = 5;
_context8.next = 5;
return _AccountsClient2.default.createUser({

@@ -289,14 +349,14 @@ password: '123456',

case 'end':
return _context6.stop();
return _context8.stop();
}
}
}, _callee6, undefined);
}, _callee8, undefined);
})));
});
describe('loginWithPassword', function () {
it('throws error if password is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() {
it('throws error if password is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() {
var transport, message;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context9.prev = _context9.next) {
case 0:

@@ -310,4 +370,4 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context7.prev = 2;
_context7.next = 5;
_context9.prev = 2;
_context9.next = 5;
return _AccountsClient2.default.loginWithPassword();

@@ -319,5 +379,5 @@

case 8:
_context7.prev = 8;
_context7.t0 = _context7['catch'](2);
message = _context7.t0.message;
_context9.prev = 8;
_context9.t0 = _context9['catch'](2);
message = _context9.t0.message;

@@ -328,12 +388,12 @@ expect(message).toEqual('Unrecognized options for login request');

case 'end':
return _context7.stop();
return _context9.stop();
}
}
}, _callee7, undefined, [[2, 8]]);
}, _callee9, undefined, [[2, 8]]);
})));
it('throws error if user is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() {
it('throws error if user is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() {
var transport, message;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context10.prev = _context10.next) {
case 0:

@@ -347,4 +407,4 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context8.prev = 2;
_context8.next = 5;
_context10.prev = 2;
_context10.next = 5;
return _AccountsClient2.default.loginWithPassword();

@@ -356,5 +416,5 @@

case 8:
_context8.prev = 8;
_context8.t0 = _context8['catch'](2);
message = _context8.t0.message;
_context10.prev = 8;
_context10.t0 = _context10['catch'](2);
message = _context10.t0.message;

@@ -365,12 +425,12 @@ expect(message).toEqual('Unrecognized options for login request');

case 'end':
return _context8.stop();
return _context10.stop();
}
}
}, _callee8, undefined, [[2, 8]]);
}, _callee10, undefined, [[2, 8]]);
})));
it('throws error user is not a string or is an empty object', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() {
it('throws error user is not a string or is an empty object', _asyncToGenerator(regeneratorRuntime.mark(function _callee11() {
var transport, message;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context11.prev = _context11.next) {
case 0:

@@ -384,4 +444,4 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context9.prev = 2;
_context9.next = 5;
_context11.prev = 2;
_context11.next = 5;
return _AccountsClient2.default.loginWithPassword({}, 'password');

@@ -393,5 +453,5 @@

case 8:
_context9.prev = 8;
_context9.t0 = _context9['catch'](2);
message = _context9.t0.message;
_context11.prev = 8;
_context11.t0 = _context11['catch'](2);
message = _context11.t0.message;

@@ -402,12 +462,12 @@ expect(message).toEqual('Match failed');

case 'end':
return _context9.stop();
return _context11.stop();
}
}
}, _callee9, undefined, [[2, 8]]);
}, _callee11, undefined, [[2, 8]]);
})));
it('throws error password is not a string', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() {
it('throws error password is not a string', _asyncToGenerator(regeneratorRuntime.mark(function _callee12() {
var transport, message;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context12.prev = _context12.next) {
case 0:

@@ -421,4 +481,4 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context10.prev = 2;
_context10.next = 5;
_context12.prev = 2;
_context12.next = 5;
return _AccountsClient2.default.loginWithPassword({ user: 'username' }, {});

@@ -430,5 +490,5 @@

case 8:
_context10.prev = 8;
_context10.t0 = _context10['catch'](2);
message = _context10.t0.message;
_context12.prev = 8;
_context12.t0 = _context12['catch'](2);
message = _context12.t0.message;

@@ -439,12 +499,12 @@ expect(message).toEqual('Match failed');

case 'end':
return _context10.stop();
return _context12.stop();
}
}
}, _callee10, undefined, [[2, 8]]);
}, _callee12, undefined, [[2, 8]]);
})));
it('calls callback on successful login', _asyncToGenerator(regeneratorRuntime.mark(function _callee11() {
it('calls callback on successful login', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context13.prev = _context13.next) {
case 0:

@@ -459,3 +519,3 @@ transport = {

callback = jest.fn();
_context11.next = 5;
_context13.next = 5;
return _AccountsClient2.default.loginWithPassword('username', 'password', callback);

@@ -469,12 +529,12 @@

case 'end':
return _context11.stop();
return _context13.stop();
}
}
}, _callee11, undefined);
}, _callee13, undefined);
})));
it('calls transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee12() {
it('calls transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() {
var loginWithPassword, transport;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context14.prev = _context14.next) {
case 0:

@@ -489,3 +549,3 @@ loginWithPassword = jest.fn(function () {

_AccountsClient2.default.config({ history: history }, transport);
_context12.next = 5;
_context14.next = 5;
return _AccountsClient2.default.loginWithPassword('username', 'password');

@@ -500,12 +560,12 @@

case 'end':
return _context12.stop();
return _context14.stop();
}
}
}, _callee12, undefined);
}, _callee14, undefined);
})));
it('calls callback with error on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() {
it('calls callback with error on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context13.prev = _context13.next) {
switch (_context15.prev = _context15.next) {
case 0:

@@ -520,4 +580,4 @@ transport = {

callback = jest.fn();
_context13.prev = 3;
_context13.next = 6;
_context15.prev = 3;
_context15.next = 6;
return _AccountsClient2.default.loginWithPassword('username', 'password', callback);

@@ -529,4 +589,4 @@

case 9:
_context13.prev = 9;
_context13.t0 = _context13['catch'](3);
_context15.prev = 9;
_context15.t0 = _context15['catch'](3);

@@ -538,12 +598,12 @@ expect(callback.mock.calls.length).toEqual(1);

case 'end':
return _context13.stop();
return _context15.stop();
}
}
}, _callee13, undefined, [[3, 9]]);
}, _callee15, undefined, [[3, 9]]);
})));
it('sets loggingIn flag to false on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() {
it('sets loggingIn flag to false on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() {
var transport;
return regeneratorRuntime.wrap(function _callee14$(_context14) {
return regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context14.prev = _context14.next) {
switch (_context16.prev = _context16.next) {
case 0:

@@ -557,4 +617,4 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context14.prev = 2;
_context14.next = 5;
_context16.prev = 2;
_context16.next = 5;
return _AccountsClient2.default.loginWithPassword('username', 'password');

@@ -566,4 +626,4 @@

case 8:
_context14.prev = 8;
_context14.t0 = _context14['catch'](2);
_context16.prev = 8;
_context16.t0 = _context16['catch'](2);

@@ -574,12 +634,12 @@ expect(_AccountsClient2.default.loggingIn()).toBe(false);

case 'end':
return _context14.stop();
return _context16.stop();
}
}
}, _callee14, undefined, [[2, 8]]);
}, _callee16, undefined, [[2, 8]]);
})));
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() {
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() {
var transport;
return regeneratorRuntime.wrap(function _callee15$(_context15) {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context15.prev = _context15.next) {
switch (_context17.prev = _context17.next) {
case 0:

@@ -593,3 +653,3 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context15.next = 4;
_context17.next = 4;
return _AccountsClient2.default.loginWithPassword('username', 'password');

@@ -603,13 +663,13 @@

case 'end':
return _context15.stop();
return _context17.stop();
}
}
}, _callee15, undefined);
}, _callee17, undefined);
})));
it('fetch tokens from storage when storage is async', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() {
it('should return tokens in a sync return value', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() {
var transport, tokens;
return regeneratorRuntime.wrap(function _callee16$(_context16) {
return regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) {
switch (_context16.prev = _context16.next) {
switch (_context18.prev = _context18.next) {
case 0:

@@ -621,5 +681,4 @@ transport = {

};
_AccountsClient2.default.config({
_context18.next = 3;
return _AccountsClient2.default.config({
history: history,

@@ -633,24 +692,20 @@ tokenStorage: {

_context16.next = 4;
return _AccountsClient2.default.tokens();
case 3:
tokens = _AccountsClient2.default.tokens();
case 4:
tokens = _context16.sent;
expect(tokens.accessToken).toBe('testValue');
expect(tokens.refreshToken).toBe('testValue');
case 7:
case 6:
case 'end':
return _context16.stop();
return _context18.stop();
}
}
}, _callee16, undefined);
}, _callee18, undefined);
})));
it('fetch tokens from storage when storage is sync', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() {
var transport, tokens;
return regeneratorRuntime.wrap(function _callee17$(_context17) {
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() {
var transport;
return regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {
switch (_context17.prev = _context17.next) {
switch (_context19.prev = _context19.next) {
case 0:

@@ -663,34 +718,21 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context19.next = 4;
return _AccountsClient2.default.loginWithPassword('username', 'password');
_AccountsClient2.default.config({
history: history,
tokenStorage: {
getItem: function getItem() {
return 'testValue';
}
}
}, transport);
_context17.next = 4;
return _AccountsClient2.default.tokens();
case 4:
tokens = _context17.sent;
expect(_AccountsClient2.default.instance.getState().get('user')).toEqual((0, _immutable.Map)(_extends({}, loggedInUser.user)));
expect(tokens.accessToken).toBe('testValue');
expect(tokens.refreshToken).toBe('testValue');
case 7:
case 5:
case 'end':
return _context17.stop();
return _context19.stop();
}
}
}, _callee17, undefined);
}, _callee19, undefined);
})));
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() {
it('stores tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() {
var transport;
return regeneratorRuntime.wrap(function _callee18$(_context18) {
return regeneratorRuntime.wrap(function _callee20$(_context20) {
while (1) {
switch (_context18.prev = _context18.next) {
switch (_context20.prev = _context20.next) {
case 0:

@@ -704,48 +746,59 @@ transport = {

_AccountsClient2.default.config({ history: history }, transport);
_context18.next = 4;
_context20.next = 4;
return _AccountsClient2.default.loginWithPassword('username', 'password');
case 4:
expect(_AccountsClient2.default.instance.getState().get('user')).toEqual((0, _immutable.Map)(_extends({}, loggedInUser.user)));
expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual((0, _immutable.Map)(_extends({}, loggedInUser.tokens)));
case 5:
case 'end':
return _context18.stop();
return _context20.stop();
}
}
}, _callee18, undefined);
}, _callee20, undefined);
})));
it('stores tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() {
var transport;
return regeneratorRuntime.wrap(function _callee19$(_context19) {
it('can hash password with specified algorithm', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() {
var loginWithPassword, transport, hashed;
return regeneratorRuntime.wrap(function _callee21$(_context21) {
while (1) {
switch (_context19.prev = _context19.next) {
switch (_context21.prev = _context21.next) {
case 0:
loginWithPassword = jest.fn(function () {
return Promise.resolve(loggedInUser);
});
transport = {
loginWithPassword: function loginWithPassword() {
return Promise.resolve(loggedInUser);
}
loginWithPassword: loginWithPassword
};
_AccountsClient2.default.config({ history: history }, transport);
_context19.next = 4;
_AccountsClient2.default.config({
history: history,
passwordHashAlgorithm: 'sha256'
}, transport);
hashed = {
digest: _crypto2.default.createHash('sha256').update('password').digest('hex'),
algorithm: 'sha256'
};
_context21.next = 6;
return _AccountsClient2.default.loginWithPassword('username', 'password');
case 4:
expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual((0, _immutable.Map)(_extends({}, loggedInUser.tokens)));
case 6:
expect(loginWithPassword.mock.calls[0][0]).toEqual('username');
expect(loginWithPassword.mock.calls[0][1]).toEqual(hashed);
expect(loginWithPassword.mock.calls.length).toEqual(1);
case 5:
case 9:
case 'end':
return _context19.stop();
return _context21.stop();
}
}
}, _callee19, undefined);
}, _callee21, undefined);
})));
});
describe('logout', function () {
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() {
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee20$(_context20) {
return regeneratorRuntime.wrap(function _callee22$(_context22) {
while (1) {
switch (_context20.prev = _context20.next) {
switch (_context22.prev = _context22.next) {
case 0:

@@ -760,3 +813,3 @@ transport = {

callback = jest.fn();
_context20.next = 5;
_context22.next = 5;
return _AccountsClient2.default.logout(callback);

@@ -769,12 +822,12 @@

case 'end':
return _context20.stop();
return _context22.stop();
}
}
}, _callee20, undefined);
}, _callee22, undefined);
})));
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() {
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() {
var onSignedOutHook, transport;
return regeneratorRuntime.wrap(function _callee21$(_context21) {
return regeneratorRuntime.wrap(function _callee23$(_context23) {
while (1) {
switch (_context21.prev = _context21.next) {
switch (_context23.prev = _context23.next) {
case 0:

@@ -789,3 +842,3 @@ onSignedOutHook = jest.fn();

_AccountsClient2.default.config({ history: history, onSignedOutHook: onSignedOutHook }, transport);
_context21.next = 5;
_context23.next = 5;
return _AccountsClient2.default.logout();

@@ -798,13 +851,13 @@

case 'end':
return _context21.stop();
return _context23.stop();
}
}
}, _callee21, undefined);
}, _callee23, undefined);
})));
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() {
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee22$(_context22) {
return regeneratorRuntime.wrap(function _callee24$(_context24) {
while (1) {
switch (_context22.prev = _context22.next) {
switch (_context24.prev = _context24.next) {
case 0:

@@ -816,34 +869,39 @@ transport = {

};
_context24.next = 3;
return _AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } });
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } });
_AccountsClient2.default.config({ history: history }, transport);
case 3:
_context24.next = 5;
return _AccountsClient2.default.config({ history: history }, transport);
case 5:
callback = jest.fn();
_context22.prev = 4;
_context22.next = 7;
_context24.prev = 6;
_context24.next = 9;
return _AccountsClient2.default.logout(callback);
case 7:
case 9:
throw new Error();
case 10:
_context22.prev = 10;
_context22.t0 = _context22['catch'](4);
case 12:
_context24.prev = 12;
_context24.t0 = _context24['catch'](6);
expect(_context22.t0.message).toEqual('error message');
expect(_context24.t0.message).toEqual('error message');
expect(callback.mock.calls.length).toEqual(1);
expect(callback.mock.calls[0][0]).toEqual({ message: 'error message' });
case 15:
case 17:
case 'end':
return _context22.stop();
return _context24.stop();
}
}
}, _callee22, undefined, [[4, 10]]);
}, _callee24, undefined, [[6, 12]]);
})));
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() {
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee23$(_context23) {
return regeneratorRuntime.wrap(function _callee25$(_context25) {
while (1) {
switch (_context23.prev = _context23.next) {
switch (_context25.prev = _context25.next) {
case 0:

@@ -859,4 +917,4 @@ transport = {

callback = jest.fn();
_context23.prev = 4;
_context23.next = 7;
_context25.prev = 4;
_context25.next = 7;
return _AccountsClient2.default.logout(callback);

@@ -868,4 +926,4 @@

case 10:
_context23.prev = 10;
_context23.t0 = _context23['catch'](4);
_context25.prev = 10;
_context25.t0 = _context25['catch'](4);

@@ -876,12 +934,12 @@ expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual(null);

case 'end':
return _context23.stop();
return _context25.stop();
}
}
}, _callee23, undefined, [[4, 10]]);
}, _callee25, undefined, [[4, 10]]);
})));
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() {
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() {
var transport, callback;
return regeneratorRuntime.wrap(function _callee24$(_context24) {
return regeneratorRuntime.wrap(function _callee26$(_context26) {
while (1) {
switch (_context24.prev = _context24.next) {
switch (_context26.prev = _context26.next) {
case 0:

@@ -897,4 +955,4 @@ transport = {

callback = jest.fn();
_context24.prev = 4;
_context24.next = 7;
_context26.prev = 4;
_context26.next = 7;
return _AccountsClient2.default.logout(callback);

@@ -906,4 +964,4 @@

case 10:
_context24.prev = 10;
_context24.t0 = _context24['catch'](4);
_context26.prev = 10;
_context26.t0 = _context26['catch'](4);

@@ -914,18 +972,18 @@ expect(_AccountsClient2.default.instance.getState().get('user')).toEqual(null);

case 'end':
return _context24.stop();
return _context26.stop();
}
}
}, _callee24, undefined, [[4, 10]]);
}, _callee26, undefined, [[4, 10]]);
})));
});
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() {
return regeneratorRuntime.wrap(function _callee27$(_context27) {
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() {
return regeneratorRuntime.wrap(function _callee29$(_context29) {
while (1) {
switch (_context27.prev = _context27.next) {
switch (_context29.prev = _context29.next) {
case 0:
// TODO test that user and tokens are cleared if refreshToken is expired
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() {
return regeneratorRuntime.wrap(function _callee25$(_context25) {
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() {
return regeneratorRuntime.wrap(function _callee27$(_context27) {
while (1) {
switch (_context25.prev = _context25.next) {
switch (_context27.prev = _context27.next) {
case 0:

@@ -939,15 +997,15 @@ _AccountsClient2.default.config({}, {});

});
_context25.prev = 3;
_context25.next = 6;
_context27.prev = 3;
_context27.next = 6;
return _AccountsClient2.default.refreshSession();
case 6:
_context25.next = 13;
_context27.next = 13;
break;
case 8:
_context25.prev = 8;
_context25.t0 = _context25['catch'](3);
_context27.prev = 8;
_context27.t0 = _context27['catch'](3);
expect(_context25.t0.message).toEqual('no tokens provided');
expect(_context27.t0.message).toEqual('no tokens provided');
expect(_AccountsClient2.default.instance.clearTokens.mock.calls.length).toEqual(1);

@@ -958,16 +1016,19 @@ expect(_AccountsClient2.default.instance.clearUser.mock.calls.length).toEqual(1);

case 'end':
return _context25.stop();
return _context27.stop();
}
}
}, _callee25, undefined, [[3, 8]]);
}, _callee27, undefined, [[3, 8]]);
})));
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() {
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() {
var message;
return regeneratorRuntime.wrap(function _callee26$(_context26) {
return regeneratorRuntime.wrap(function _callee28$(_context28) {
while (1) {
switch (_context26.prev = _context26.next) {
switch (_context28.prev = _context28.next) {
case 0:
_AccountsClient2.default.config({}, {});
localStorage.setItem('accounts:refreshToken', 'bad token');
localStorage.setItem('accounts:accessToken', 'bad token');
_context28.next = 4;
return _AccountsClient2.default.config({}, {});
case 4:
_AccountsClient2.default.instance.clearTokens = jest.fn(function () {

@@ -979,22 +1040,22 @@ return _AccountsClient2.default.instance.clearTokens;

});
_context26.prev = 5;
_context26.next = 8;
_context28.prev = 6;
_context28.next = 9;
return _AccountsClient2.default.refreshSession();
case 8:
case 9:
throw new Error();
case 11:
_context26.prev = 11;
_context26.t0 = _context26['catch'](5);
message = _context26.t0.message;
case 12:
_context28.prev = 12;
_context28.t0 = _context28['catch'](6);
message = _context28.t0.message;
expect(message).toEqual('falsy token provided');
case 15:
case 16:
case 'end':
return _context26.stop();
return _context28.stop();
}
}
}, _callee26, undefined, [[5, 11]]);
}, _callee28, undefined, [[6, 12]]);
})));

@@ -1038,14 +1099,14 @@ // it('requests a new token pair, sets the tokens and the user', async () => {

case 'end':
return _context27.stop();
return _context29.stop();
}
}
}, _callee27, undefined);
}, _callee29, undefined);
})));
describe('verifyEmail', function () {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() {
var error;
return regeneratorRuntime.wrap(function _callee28$(_context28) {
return regeneratorRuntime.wrap(function _callee30$(_context30) {
while (1) {
switch (_context28.prev = _context28.next) {
switch (_context30.prev = _context30.next) {
case 0:

@@ -1057,4 +1118,4 @@ error = 'something bad';

} });
_context28.prev = 2;
_context28.next = 5;
_context30.prev = 2;
_context30.next = 5;
return _AccountsClient2.default.verifyEmail();

@@ -1066,20 +1127,20 @@

case 8:
_context28.prev = 8;
_context28.t0 = _context28['catch'](2);
_context30.prev = 8;
_context30.t0 = _context30['catch'](2);
expect(_context28.t0.message).toEqual(error);
expect(_context30.t0.message).toEqual(error);
case 11:
case 'end':
return _context28.stop();
return _context30.stop();
}
}
}, _callee28, undefined, [[2, 8]]);
}, _callee30, undefined, [[2, 8]]);
})));
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() {
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() {
var mock;
return regeneratorRuntime.wrap(function _callee29$(_context29) {
return regeneratorRuntime.wrap(function _callee31$(_context31) {
while (1) {
switch (_context29.prev = _context29.next) {
switch (_context31.prev = _context31.next) {
case 0:

@@ -1091,3 +1152,3 @@ mock = jest.fn(function () {

_AccountsClient2.default.config({}, { verifyEmail: mock });
_context29.next = 4;
_context31.next = 4;
return _AccountsClient2.default.verifyEmail('token');

@@ -1101,6 +1162,6 @@

case 'end':
return _context29.stop();
return _context31.stop();
}
}
}, _callee29, undefined);
}, _callee31, undefined);
})));

@@ -1110,15 +1171,47 @@ });

describe('resetPassword', function () {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() {
var error;
return regeneratorRuntime.wrap(function _callee30$(_context30) {
return regeneratorRuntime.wrap(function _callee32$(_context32) {
while (1) {
switch (_context30.prev = _context30.next) {
switch (_context32.prev = _context32.next) {
case 0:
error = 'something bad';
_AccountsClient2.default.config({}, { resetPassword: function resetPassword() {
_context32.next = 3;
return _AccountsClient2.default.config({}, { resetPassword: function resetPassword() {
return Promise.reject({ message: error });
} });
_context30.prev = 2;
_context30.next = 5;
case 3:
_context32.prev = 3;
_context32.next = 6;
return _AccountsClient2.default.resetPassword('badtoken', 'password');
case 6:
throw new Error();
case 9:
_context32.prev = 9;
_context32.t0 = _context32['catch'](3);
expect(_context32.t0.message).toEqual(error);
case 12:
case 'end':
return _context32.stop();
}
}
}, _callee32, undefined, [[3, 9]]);
})));
it('throws if password is invalid', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() {
return regeneratorRuntime.wrap(function _callee33$(_context33) {
while (1) {
switch (_context33.prev = _context33.next) {
case 0:
_context33.next = 2;
return _AccountsClient2.default.config({}, {});
case 2:
_context33.prev = 2;
_context33.next = 5;
return _AccountsClient2.default.resetPassword();

@@ -1130,20 +1223,20 @@

case 8:
_context30.prev = 8;
_context30.t0 = _context30['catch'](2);
_context33.prev = 8;
_context33.t0 = _context33['catch'](2);
expect(_context30.t0.message).toEqual(error);
expect(_context33.t0.message).toEqual('Password is invalid!');
case 11:
case 'end':
return _context30.stop();
return _context33.stop();
}
}
}, _callee30, undefined, [[2, 8]]);
}, _callee33, undefined, [[2, 8]]);
})));
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() {
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() {
var mock;
return regeneratorRuntime.wrap(function _callee31$(_context31) {
return regeneratorRuntime.wrap(function _callee34$(_context34) {
while (1) {
switch (_context31.prev = _context31.next) {
switch (_context34.prev = _context34.next) {
case 0:

@@ -1155,3 +1248,3 @@ mock = jest.fn(function () {

_AccountsClient2.default.config({}, { resetPassword: mock });
_context31.next = 4;
_context34.next = 4;
return _AccountsClient2.default.resetPassword('token', 'newPassword');

@@ -1166,6 +1259,6 @@

case 'end':
return _context31.stop();
return _context34.stop();
}
}
}, _callee31, undefined);
}, _callee34, undefined);
})));

@@ -1175,7 +1268,7 @@ });

describe('requestPasswordReset', function () {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() {
var error;
return regeneratorRuntime.wrap(function _callee32$(_context32) {
return regeneratorRuntime.wrap(function _callee35$(_context35) {
while (1) {
switch (_context32.prev = _context32.next) {
switch (_context35.prev = _context35.next) {
case 0:

@@ -1187,5 +1280,5 @@ error = 'something bad';

} });
_context32.prev = 2;
_context32.next = 5;
return _AccountsClient2.default.requestPasswordReset();
_context35.prev = 2;
_context35.next = 5;
return _AccountsClient2.default.requestPasswordReset('email@g.co');

@@ -1196,20 +1289,20 @@ case 5:

case 8:
_context32.prev = 8;
_context32.t0 = _context32['catch'](2);
_context35.prev = 8;
_context35.t0 = _context35['catch'](2);
expect(_context32.t0.message).toEqual(error);
expect(_context35.t0.message).toEqual(error);
case 11:
case 'end':
return _context32.stop();
return _context35.stop();
}
}
}, _callee32, undefined, [[2, 8]]);
}, _callee35, undefined, [[2, 8]]);
})));
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() {
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee36() {
var mock;
return regeneratorRuntime.wrap(function _callee33$(_context33) {
return regeneratorRuntime.wrap(function _callee36$(_context36) {
while (1) {
switch (_context33.prev = _context33.next) {
switch (_context36.prev = _context36.next) {
case 0:

@@ -1221,24 +1314,55 @@ mock = jest.fn(function () {

_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock });
_context33.next = 4;
return _AccountsClient2.default.requestPasswordReset('email');
_context36.next = 4;
return _AccountsClient2.default.requestPasswordReset('email@g.co');
case 4:
expect(mock.mock.calls.length).toEqual(1);
expect(mock.mock.calls[0][0]).toEqual('email');
expect(mock.mock.calls[0][0]).toEqual('email@g.co');
case 6:
case 'end':
return _context33.stop();
return _context36.stop();
}
}
}, _callee33, undefined);
}, _callee36, undefined);
})));
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() {
var mock;
return regeneratorRuntime.wrap(function _callee37$(_context37) {
while (1) {
switch (_context37.prev = _context37.next) {
case 0:
mock = jest.fn();
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock });
_context37.prev = 2;
_context37.next = 5;
return _AccountsClient2.default.requestPasswordReset('email');
case 5:
throw new Error();
case 8:
_context37.prev = 8;
_context37.t0 = _context37['catch'](2);
expect(_context37.t0.message).toEqual('Valid email must be provided');
expect(mock.mock.calls.length).toEqual(0);
case 12:
case 'end':
return _context37.stop();
}
}
}, _callee37, undefined, [[2, 8]]);
})));
});
describe('requestVerificationEmail', function () {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() {
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() {
var error;
return regeneratorRuntime.wrap(function _callee34$(_context34) {
return regeneratorRuntime.wrap(function _callee38$(_context38) {
while (1) {
switch (_context34.prev = _context34.next) {
switch (_context38.prev = _context38.next) {
case 0:

@@ -1250,5 +1374,5 @@ error = 'something bad';

} });
_context34.prev = 2;
_context34.next = 5;
return _AccountsClient2.default.requestVerificationEmail();
_context38.prev = 2;
_context38.next = 5;
return _AccountsClient2.default.requestVerificationEmail('email@g.co');

@@ -1259,20 +1383,20 @@ case 5:

case 8:
_context34.prev = 8;
_context34.t0 = _context34['catch'](2);
_context38.prev = 8;
_context38.t0 = _context38['catch'](2);
expect(_context34.t0.message).toEqual(error);
expect(_context38.t0.message).toEqual(error);
case 11:
case 'end':
return _context34.stop();
return _context38.stop();
}
}
}, _callee34, undefined, [[2, 8]]);
}, _callee38, undefined, [[2, 8]]);
})));
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() {
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee39() {
var mock;
return regeneratorRuntime.wrap(function _callee35$(_context35) {
return regeneratorRuntime.wrap(function _callee39$(_context39) {
while (1) {
switch (_context35.prev = _context35.next) {
switch (_context39.prev = _context39.next) {
case 0:

@@ -1284,17 +1408,48 @@ mock = jest.fn(function () {

_AccountsClient2.default.config({}, { sendVerificationEmail: mock });
_context35.next = 4;
return _AccountsClient2.default.requestVerificationEmail('email');
_context39.next = 4;
return _AccountsClient2.default.requestVerificationEmail('email@g.co');
case 4:
expect(mock.mock.calls.length).toEqual(1);
expect(mock.mock.calls[0][0]).toEqual('email');
expect(mock.mock.calls[0][0]).toEqual('email@g.co');
case 6:
case 'end':
return _context35.stop();
return _context39.stop();
}
}
}, _callee35, undefined);
}, _callee39, undefined);
})));
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee40() {
var mock;
return regeneratorRuntime.wrap(function _callee40$(_context40) {
while (1) {
switch (_context40.prev = _context40.next) {
case 0:
mock = jest.fn();
_AccountsClient2.default.config({}, { sendVerificationEmail: mock });
_context40.prev = 2;
_context40.next = 5;
return _AccountsClient2.default.requestVerificationEmail('email');
case 5:
throw new Error();
case 8:
_context40.prev = 8;
_context40.t0 = _context40['catch'](2);
expect(_context40.t0.message).toEqual('Valid email must be provided');
expect(mock.mock.calls.length).toEqual(0);
case 12:
case 'end':
return _context40.stop();
}
}
}, _callee40, undefined, [[2, 8]]);
})));
});
});

@@ -45,17 +45,17 @@ 'use strict';

onEnrollAccountHook: function onEnrollAccountHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/');
},
onResetPasswordHook: function onResetPasswordHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/');
},
onVerifyEmailHook: function onVerifyEmailHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().profilePath);
return (0, _redirect2.default)(_AccountsClient2.default.options().profilePath || '/');
},
onSignedInHook: function onSignedInHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().homePath);
return (0, _redirect2.default)(_AccountsClient2.default.options().homePath || '/');
},
onSignedOutHook: function onSignedOutHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().signOutPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().signOutPath || '/');
},
loginOnSignUp: true
});

@@ -13,2 +13,3 @@ 'use strict';

// $FlowFixMe
exports.default = function (path) {

@@ -15,0 +16,0 @@ return _AccountsClient2.default.options().history.push(path);

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"));
module.exports = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"), require("lodash/isString"), require("crypto-js"));
else if(typeof define === 'function' && define.amd)
define(["babel-runtime/helpers/extends", "babel-runtime/regenerator", "babel-runtime/core-js/promise", "babel-runtime/helpers/asyncToGenerator", "babel-runtime/helpers/defineProperty", "babel-runtime/helpers/classCallCheck", "babel-runtime/helpers/createClass", "lodash", "jwt-decode", "@accounts/common", "babel-runtime/helpers/toConsumableArray", "redux", "immutable", "redux-immutable"], factory);
define(["babel-runtime/helpers/extends", "babel-runtime/regenerator", "babel-runtime/core-js/promise", "babel-runtime/helpers/asyncToGenerator", "babel-runtime/helpers/defineProperty", "babel-runtime/helpers/classCallCheck", "babel-runtime/helpers/createClass", "lodash", "jwt-decode", "@accounts/common", "babel-runtime/helpers/toConsumableArray", "redux", "immutable", "redux-immutable", "lodash/isString", "crypto-js"], factory);
else if(typeof exports === 'object')
exports["@accounts/client"] = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"));
exports["@accounts/client"] = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"), require("lodash/isString"), require("crypto-js"));
else
root["@accounts/client"] = factory(root["babel-runtime/helpers/extends"], root["babel-runtime/regenerator"], root["babel-runtime/core-js/promise"], root["babel-runtime/helpers/asyncToGenerator"], root["babel-runtime/helpers/defineProperty"], root["babel-runtime/helpers/classCallCheck"], root["babel-runtime/helpers/createClass"], root["lodash"], root["jwt-decode"], root["@accounts/common"], root["babel-runtime/helpers/toConsumableArray"], root["redux"], root["immutable"], root["redux-immutable"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_11__, __WEBPACK_EXTERNAL_MODULE_15__, __WEBPACK_EXTERNAL_MODULE_16__, __WEBPACK_EXTERNAL_MODULE_17__, __WEBPACK_EXTERNAL_MODULE_18__) {
root["@accounts/client"] = factory(root["babel-runtime/helpers/extends"], root["babel-runtime/regenerator"], root["babel-runtime/core-js/promise"], root["babel-runtime/helpers/asyncToGenerator"], root["babel-runtime/helpers/defineProperty"], root["babel-runtime/helpers/classCallCheck"], root["babel-runtime/helpers/createClass"], root["lodash"], root["jwt-decode"], root["@accounts/common"], root["babel-runtime/helpers/toConsumableArray"], root["redux"], root["immutable"], root["redux-immutable"], root["lodash/isString"], root["crypto-js"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_11__, __WEBPACK_EXTERNAL_MODULE_15__, __WEBPACK_EXTERNAL_MODULE_16__, __WEBPACK_EXTERNAL_MODULE_17__, __WEBPACK_EXTERNAL_MODULE_18__, __WEBPACK_EXTERNAL_MODULE_21__, __WEBPACK_EXTERNAL_MODULE_22__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -142,2 +142,4 @@ /******/ // The module cache

var _encryption = __webpack_require__(20);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -161,3 +163,3 @@

this.options = options;
this.storage = options.tokenStorage;
this.storage = options.tokenStorage || _config3.default.tokenStorage;
if (!transport) {

@@ -171,4 +173,5 @@ throw new _common.AccountsError('A REST or GraphQL transport is required');

var reduxStoreKey = options.reduxStoreKey || _config3.default.reduxStoreKey;
this.store = options.store || (0, _createStore2.default)({
reducers: (0, _defineProperty3.default)({}, options.reduxStoreKey, _module2.default),
reducers: (0, _defineProperty3.default)({}, reduxStoreKey, _module2.default),
middleware: middleware

@@ -262,11 +265,6 @@ });

}, {
key: 'user',
value: function user() {
var user = this.getState().get('user');
return user ? user.toJS() : null;
}
}, {
key: 'tokens',
key: 'loadTokensFromStorage',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4() {
var tokens;
return _regenerator2.default.wrap(function _callee4$(_context4) {

@@ -286,8 +284,10 @@ while (1) {

_context4.t1 = _context4.sent;
return _context4.abrupt('return', {
tokens = {
accessToken: _context4.t0,
refreshToken: _context4.t1
});
};
case 7:
this.store.dispatch((0, _module.setTokens)(tokens));
case 8:
case 'end':

@@ -300,9 +300,26 @@ return _context4.stop();

function tokens() {
function loadTokensFromStorage() {
return _ref4.apply(this, arguments);
}
return tokens;
return loadTokensFromStorage;
}()
}, {
key: 'user',
value: function user() {
var user = this.getState().get('user');
return user ? user.toJS() : null;
}
}, {
key: 'tokens',
value: function tokens() {
var tokens = this.getState().get('tokens');
return tokens ? tokens.toJS() : {
accessToken: null,
refreshToken: null
};
}
}, {
key: 'clearTokens',

@@ -411,3 +428,3 @@ value: function () {

if (!(accessToken && refreshToken)) {
_context7.next = 30;
_context7.next = 33;
break;

@@ -417,2 +434,4 @@ }

_context7.prev = 6;
this.store.dispatch((0, _module.loggingIn)(true));
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken);

@@ -423,3 +442,3 @@ currentTime = Date.now() / 1000;

if (!(decodedRefreshToken.exp < currentTime)) {
_context7.next = 14;
_context7.next = 15;
break;

@@ -430,26 +449,30 @@ }

this.clearUser();
_context7.next = 21;
_context7.next = 23;
break;
case 14:
_context7.next = 16;
case 15:
_context7.next = 17;
return this.transport.refreshTokens(accessToken, refreshToken);
case 16:
case 17:
refreshedSession = _context7.sent;
_context7.next = 19;
this.store.dispatch((0, _module.loggingIn)(false));
_context7.next = 21;
return this.storeTokens(refreshedSession);
case 19:
case 21:
this.store.dispatch((0, _module.setTokens)(refreshedSession.tokens));
this.store.dispatch((0, _module.setUser)(refreshedSession.user));
case 21:
_context7.next = 28;
case 23:
_context7.next = 31;
break;
case 23:
_context7.prev = 23;
case 25:
_context7.prev = 25;
_context7.t0 = _context7['catch'](6);
this.store.dispatch((0, _module.loggingIn)(false));
this.clearTokens();

@@ -459,7 +482,7 @@ this.clearUser();

case 28:
_context7.next = 33;
case 31:
_context7.next = 36;
break;
case 30:
case 33:
this.clearTokens();

@@ -469,3 +492,3 @@ this.clearUser();

case 33:
case 36:
case 'end':

@@ -475,3 +498,3 @@ return _context7.stop();

}
}, _callee7, this, [[6, 23]]);
}, _callee7, this, [[6, 25]]);
}));

@@ -489,3 +512,3 @@

var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(user, callback) {
var userId;
var hashAlgorithm, password, userToCreate, userId;
return _regenerator2.default.wrap(function _callee8$(_context8) {

@@ -506,3 +529,3 @@ while (1) {

case 2:
if (_common.validators.validatePassword(user.password)) {
if (!(!user.password || (0, _lodash.isString)(user.password) && !_common.validators.validatePassword(user.password))) {
_context8.next = 4;

@@ -523,7 +546,10 @@ break;

case 6:
_context8.prev = 6;
_context8.next = 9;
return this.transport.createUser(user);
hashAlgorithm = this.options.passwordHashAlgorithm;
password = user.password && hashAlgorithm ? (0, _encryption.hashPassword)(user.password, hashAlgorithm) : user.password;
userToCreate = (0, _extends3.default)({}, user, { password: password });
_context8.prev = 9;
_context8.next = 12;
return this.transport.createUser(userToCreate);
case 9:
case 12:
userId = _context8.sent;

@@ -534,12 +560,13 @@

}
_context8.next = 13;
_context8.next = 16;
return this.loginWithPassword({ id: userId }, user.password);
case 13:
_context8.next = 19;
case 16:
_context8.next = 22;
break;
case 15:
_context8.prev = 15;
_context8.t0 = _context8['catch'](6);
case 18:
_context8.prev = 18;
_context8.t0 = _context8['catch'](9);

@@ -551,3 +578,3 @@ if (callback && (0, _lodash.isFunction)(callback)) {

case 19:
case 22:
case 'end':

@@ -557,3 +584,3 @@ return _context8.stop();

}
}, _callee8, this, [[6, 15]]);
}, _callee8, this, [[9, 18]]);
}));

@@ -571,3 +598,3 @@

var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(user, password, callback) {
var res;
var hashAlgorithm, pass, res;
return _regenerator2.default.wrap(function _callee9$(_context9) {

@@ -596,16 +623,23 @@ while (1) {

_context9.prev = 5;
_context9.next = 8;
return this.transport.loginWithPassword(user, password);
hashAlgorithm = this.options.passwordHashAlgorithm;
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password;
_context9.next = 10;
return this.transport.loginWithPassword(user, pass);
case 8:
case 10:
res = _context9.sent;
this.store.dispatch((0, _module.loggingIn)(false));
_context9.next = 12;
_context9.next = 14;
return this.storeTokens(res);
case 12:
case 14:
this.store.dispatch((0, _module.setTokens)(res.tokens));
this.store.dispatch((0, _module.setUser)(res.user));
this.options.onSignedInHook();
if (this.options.onSignedInHook && (0, _lodash.isFunction)(this.options.onSignedInHook)) {
this.options.onSignedInHook();
}
if (callback && (0, _lodash.isFunction)(callback)) {

@@ -617,4 +651,4 @@ callback(null, res);

case 19:
_context9.prev = 19;
case 21:
_context9.prev = 21;
_context9.t0 = _context9['catch'](5);

@@ -628,3 +662,3 @@

case 24:
case 26:
case 'end':

@@ -634,3 +668,3 @@ return _context9.stop();

}
}, _callee9, this, [[5, 19]]);
}, _callee9, this, [[5, 21]]);
}));

@@ -687,3 +721,6 @@

}
this.options.onSignedOutHook();
if (this.options.onSignedOutHook) {
this.options.onSignedOutHook();
}
_context10.next = 18;

@@ -754,2 +791,3 @@ break;

var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(token, newPassword) {
var hashAlgorithm, password;
return _regenerator2.default.wrap(function _callee12$(_context12) {

@@ -759,16 +797,26 @@ while (1) {

case 0:
_context12.prev = 0;
_context12.next = 3;
return this.transport.resetPassword(token, newPassword);
if (_common.validators.validatePassword(newPassword)) {
_context12.next = 2;
break;
}
case 3:
_context12.next = 8;
throw new _common.AccountsError('Password is invalid!');
case 2:
hashAlgorithm = this.options.passwordHashAlgorithm;
password = hashAlgorithm ? (0, _encryption.hashPassword)(newPassword, hashAlgorithm) : newPassword;
_context12.prev = 4;
_context12.next = 7;
return this.transport.resetPassword(token, password);
case 7:
_context12.next = 12;
break;
case 5:
_context12.prev = 5;
_context12.t0 = _context12['catch'](0);
case 9:
_context12.prev = 9;
_context12.t0 = _context12['catch'](4);
throw new _common.AccountsError(_context12.t0.message);
case 8:
case 12:
case 'end':

@@ -778,3 +826,3 @@ return _context12.stop();

}
}, _callee12, this, [[0, 5]]);
}, _callee12, this, [[4, 9]]);
}));

@@ -796,16 +844,24 @@

case 0:
_context13.prev = 0;
_context13.next = 3;
if (_common.validators.validateEmail(email)) {
_context13.next = 2;
break;
}
throw new _common.AccountsError('Valid email must be provided');
case 2:
_context13.prev = 2;
_context13.next = 5;
return this.transport.sendResetPasswordEmail(email);
case 3:
_context13.next = 8;
case 5:
_context13.next = 10;
break;
case 5:
_context13.prev = 5;
_context13.t0 = _context13['catch'](0);
case 7:
_context13.prev = 7;
_context13.t0 = _context13['catch'](2);
throw new _common.AccountsError(_context13.t0.message);
case 8:
case 10:
case 'end':

@@ -815,3 +871,3 @@ return _context13.stop();

}
}, _callee13, this, [[0, 5]]);
}, _callee13, this, [[2, 7]]);
}));

@@ -833,16 +889,24 @@

case 0:
_context14.prev = 0;
_context14.next = 3;
if (_common.validators.validateEmail(email)) {
_context14.next = 2;
break;
}
throw new _common.AccountsError('Valid email must be provided');
case 2:
_context14.prev = 2;
_context14.next = 5;
return this.transport.sendVerificationEmail(email);
case 3:
_context14.next = 8;
case 5:
_context14.next = 10;
break;
case 5:
_context14.prev = 5;
_context14.t0 = _context14['catch'](0);
case 7:
_context14.prev = 7;
_context14.t0 = _context14['catch'](2);
throw new _common.AccountsError(_context14.t0.message);
case 8:
case 10:
case 'end':

@@ -852,3 +916,3 @@ return _context14.stop();

}
}, _callee14, this, [[0, 5]]);
}, _callee14, this, [[2, 7]]);
}));

@@ -870,3 +934,22 @@

config: function config(options, transport) {
this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport);
var _this = this;
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15() {
return _regenerator2.default.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport);
return _context15.abrupt('return', _this.instance.loadTokensFromStorage().then(function () {
return _this.instance;
}));
case 2:
case 'end':
return _context15.stop();
}
}
}, _callee15, _this);
}))();
},

@@ -1038,15 +1121,15 @@ user: function user() {

onEnrollAccountHook: function onEnrollAccountHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/');
},
onResetPasswordHook: function onResetPasswordHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/');
},
onVerifyEmailHook: function onVerifyEmailHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().profilePath);
return (0, _redirect2.default)(_AccountsClient2.default.options().profilePath || '/');
},
onSignedInHook: function onSignedInHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().homePath);
return (0, _redirect2.default)(_AccountsClient2.default.options().homePath || '/');
},
onSignedOutHook: function onSignedOutHook() {
return (0, _redirect2.default)(_AccountsClient2.default.options().signOutPath);
return (0, _redirect2.default)(_AccountsClient2.default.options().signOutPath || '/');
},

@@ -1072,2 +1155,3 @@ loginOnSignUp: true

// $FlowFixMe
exports.default = function (path) {

@@ -1244,2 +1328,59 @@ return _AccountsClient2.default.options().history.push(path);

/***/ },
/* 20 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hashPassword = undefined;
var _isString = __webpack_require__(21);
var _isString2 = _interopRequireDefault(_isString);
var _cryptoJs = __webpack_require__(22);
var _cryptoJs2 = _interopRequireDefault(_cryptoJs);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var mapHashConstant = {
sha: 'SHA',
sha1: 'SHA1',
sha224: 'SHA224',
sha256: 'SHA256',
sha384: 'SHA384',
sha512: 'SHA512',
md5: 'MD5',
ripemd160: 'RIPEMD160'
};
var hashPassword = exports.hashPassword = function hashPassword(password, algorithm) {
if ((0, _isString2.default)(password)) {
var cryptoAlgoKey = mapHashConstant[algorithm];
var cryptoFunction = _cryptoJs2.default[cryptoAlgoKey];
return {
digest: cryptoFunction(password).toString(),
algorithm: algorithm
};
}
// Prehashed password object
return password;
};
/***/ },
/* 21 */
/***/ function(module, exports) {
module.exports = require("lodash/isString");
/***/ },
/* 22 */
/***/ function(module, exports) {
module.exports = require("crypto-js");
/***/ }

@@ -1246,0 +1387,0 @@ /******/ ])

{
"name": "@accounts/client",
"version": "0.0.9",
"version": "0.0.10-alpha.11535f01",
"description": "Fullstack authentication and accounts-management",

@@ -22,3 +22,5 @@ "main": "lib/index.js",

"flow:gen": "flow gen-flow-files ./src/index.js > ./lib/index.js.flow",
"flow:prepublish": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib-es6/g\" | sed \"s/js/js\\.flow/g\"`; done",
"flow:prepublish": "npm run flow:cplib && npm run flow:cplibes6",
"flow:cplib": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib/g\" | sed \"s/js/js\\.flow/g\"`; done",
"flow:cplibes6": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib-es6/g\" | sed \"s/js/js\\.flow/g\"`; done",
"coverage": "npm run testonly -- --coverage",

@@ -64,3 +66,3 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"

"coveralls": "^2.11.14",
"flow-bin": "^0.39.0",
"flow-bin": "0.41.0",
"jest": "^18.0.0",

@@ -74,3 +76,4 @@ "lerna": "2.0.0-beta.32",

"dependencies": {
"@accounts/common": "^0.0.9",
"@accounts/common": "^0.0.10-alpha.11535f01",
"crypto-js": "^3.1.9-1",
"immutable": "^3.8.1",

@@ -77,0 +80,0 @@ "jwt-decode": "^2.1.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc