@accounts/client
Advanced tools
Comparing version 0.0.9 to 0.0.10-alpha.b575b352
@@ -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 | ||
@@ -304,3 +307,3 @@ }); | ||
if (!(accessToken && refreshToken)) { | ||
_context7.next = 30; | ||
_context7.next = 33; | ||
break; | ||
@@ -310,2 +313,4 @@ } | ||
_context7.prev = 6; | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken); | ||
@@ -316,3 +321,3 @@ currentTime = Date.now() / 1000; | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context7.next = 14; | ||
_context7.next = 15; | ||
break; | ||
@@ -323,26 +328,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(); | ||
@@ -352,7 +361,7 @@ this.clearUser(); | ||
case 28: | ||
_context7.next = 33; | ||
case 31: | ||
_context7.next = 36; | ||
break; | ||
case 30: | ||
case 33: | ||
this.clearTokens(); | ||
@@ -362,3 +371,3 @@ this.clearUser(); | ||
case 33: | ||
case 36: | ||
case 'end': | ||
@@ -368,3 +377,3 @@ return _context7.stop(); | ||
} | ||
}, _callee7, this, [[6, 23]]); | ||
}, _callee7, this, [[6, 25]]); | ||
})); | ||
@@ -458,3 +467,3 @@ | ||
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(user, password, callback) { | ||
var res; | ||
var hashAlgorithm, pass, res; | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
@@ -483,16 +492,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)) { | ||
@@ -504,4 +520,4 @@ callback(null, res); | ||
case 19: | ||
_context9.prev = 19; | ||
case 21: | ||
_context9.prev = 21; | ||
_context9.t0 = _context9['catch'](5); | ||
@@ -515,3 +531,3 @@ | ||
case 24: | ||
case 26: | ||
case 'end': | ||
@@ -521,3 +537,3 @@ return _context9.stop(); | ||
} | ||
}, _callee9, this, [[5, 19]]); | ||
}, _callee9, this, [[5, 21]]); | ||
})); | ||
@@ -574,3 +590,6 @@ | ||
} | ||
this.options.onSignedOutHook(); | ||
if (this.options.onSignedOutHook) { | ||
this.options.onSignedOutHook(); | ||
} | ||
_context10.next = 18; | ||
@@ -680,16 +699,24 @@ break; | ||
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': | ||
@@ -699,3 +726,3 @@ return _context13.stop(); | ||
} | ||
}, _callee13, this, [[0, 5]]); | ||
}, _callee13, this, [[2, 7]]); | ||
})); | ||
@@ -717,16 +744,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': | ||
@@ -736,3 +771,3 @@ return _context14.stop(); | ||
} | ||
}, _callee14, this, [[0, 5]]); | ||
}, _callee14, this, [[2, 7]]); | ||
})); | ||
@@ -739,0 +774,0 @@ |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _crypto = require('crypto'); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
require('./mockLocalStorage'); | ||
@@ -699,9 +703,43 @@ | ||
}))); | ||
it('can hash password with specified algorithm', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var loginWithPassword, transport, hashDigest; | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
loginWithPassword = jest.fn(function () { | ||
return Promise.resolve(loggedInUser); | ||
}); | ||
transport = { | ||
loginWithPassword: loginWithPassword | ||
}; | ||
_AccountsClient2.default.config({ | ||
history: history, | ||
passwordHashAlgorithm: 'sha256' | ||
}, transport); | ||
hashDigest = _crypto2.default.createHash('sha256').update('password').digest('hex'); | ||
_context20.next = 6; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
case 6: | ||
expect(loginWithPassword.mock.calls[0][0]).toEqual('username'); | ||
expect(loginWithPassword.mock.calls[0][1]).toEqual(hashDigest); | ||
expect(loginWithPassword.mock.calls.length).toEqual(1); | ||
case 9: | ||
case 'end': | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee20, 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 _callee21() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
@@ -716,3 +754,3 @@ transport = { | ||
callback = jest.fn(); | ||
_context20.next = 5; | ||
_context21.next = 5; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -725,12 +763,12 @@ | ||
case 'end': | ||
return _context20.stop(); | ||
return _context21.stop(); | ||
} | ||
} | ||
}, _callee20, undefined); | ||
}, _callee21, undefined); | ||
}))); | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
var onSignedOutHook, transport; | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
@@ -745,3 +783,3 @@ onSignedOutHook = jest.fn(); | ||
_AccountsClient2.default.config({ history: history, onSignedOutHook: onSignedOutHook }, transport); | ||
_context21.next = 5; | ||
_context22.next = 5; | ||
return _AccountsClient2.default.logout(); | ||
@@ -754,13 +792,13 @@ | ||
case 'end': | ||
return _context21.stop(); | ||
return _context22.stop(); | ||
} | ||
} | ||
}, _callee21, undefined); | ||
}, _callee22, 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 _callee23() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context22.prev = _context22.next) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
@@ -776,4 +814,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context22.prev = 4; | ||
_context22.next = 7; | ||
_context23.prev = 4; | ||
_context23.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -785,6 +823,6 @@ | ||
case 10: | ||
_context22.prev = 10; | ||
_context22.t0 = _context22['catch'](4); | ||
_context23.prev = 10; | ||
_context23.t0 = _context23['catch'](4); | ||
expect(_context22.t0.message).toEqual('error message'); | ||
expect(_context23.t0.message).toEqual('error message'); | ||
expect(callback.mock.calls.length).toEqual(1); | ||
@@ -795,13 +833,13 @@ expect(callback.mock.calls[0][0]).toEqual({ message: 'error message' }); | ||
case 'end': | ||
return _context22.stop(); | ||
return _context23.stop(); | ||
} | ||
} | ||
}, _callee22, undefined, [[4, 10]]); | ||
}, _callee23, undefined, [[4, 10]]); | ||
}))); | ||
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
switch (_context24.prev = _context24.next) { | ||
case 0: | ||
@@ -817,4 +855,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context23.prev = 4; | ||
_context23.next = 7; | ||
_context24.prev = 4; | ||
_context24.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -826,4 +864,4 @@ | ||
case 10: | ||
_context23.prev = 10; | ||
_context23.t0 = _context23['catch'](4); | ||
_context24.prev = 10; | ||
_context24.t0 = _context24['catch'](4); | ||
@@ -834,12 +872,12 @@ expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual(null); | ||
case 'end': | ||
return _context23.stop(); | ||
return _context24.stop(); | ||
} | ||
} | ||
}, _callee23, undefined, [[4, 10]]); | ||
}, _callee24, undefined, [[4, 10]]); | ||
}))); | ||
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
while (1) { | ||
switch (_context24.prev = _context24.next) { | ||
switch (_context25.prev = _context25.next) { | ||
case 0: | ||
@@ -855,4 +893,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context24.prev = 4; | ||
_context24.next = 7; | ||
_context25.prev = 4; | ||
_context25.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -864,4 +902,4 @@ | ||
case 10: | ||
_context24.prev = 10; | ||
_context24.t0 = _context24['catch'](4); | ||
_context25.prev = 10; | ||
_context25.t0 = _context25['catch'](4); | ||
@@ -872,18 +910,18 @@ expect(_AccountsClient2.default.instance.getState().get('user')).toEqual(null); | ||
case 'end': | ||
return _context24.stop(); | ||
return _context25.stop(); | ||
} | ||
} | ||
}, _callee24, undefined, [[4, 10]]); | ||
}, _callee25, undefined, [[4, 10]]); | ||
}))); | ||
}); | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context27.prev = _context27.next) { | ||
switch (_context28.prev = _context28.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 _callee26() { | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
while (1) { | ||
switch (_context25.prev = _context25.next) { | ||
switch (_context26.prev = _context26.next) { | ||
case 0: | ||
@@ -897,15 +935,15 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context25.prev = 3; | ||
_context25.next = 6; | ||
_context26.prev = 3; | ||
_context26.next = 6; | ||
return _AccountsClient2.default.refreshSession(); | ||
case 6: | ||
_context25.next = 13; | ||
_context26.next = 13; | ||
break; | ||
case 8: | ||
_context25.prev = 8; | ||
_context25.t0 = _context25['catch'](3); | ||
_context26.prev = 8; | ||
_context26.t0 = _context26['catch'](3); | ||
expect(_context25.t0.message).toEqual('no tokens provided'); | ||
expect(_context26.t0.message).toEqual('no tokens provided'); | ||
expect(_AccountsClient2.default.instance.clearTokens.mock.calls.length).toEqual(1); | ||
@@ -916,12 +954,12 @@ expect(_AccountsClient2.default.instance.clearUser.mock.calls.length).toEqual(1); | ||
case 'end': | ||
return _context25.stop(); | ||
return _context26.stop(); | ||
} | ||
} | ||
}, _callee25, undefined, [[3, 8]]); | ||
}, _callee26, 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 _callee27() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
while (1) { | ||
switch (_context26.prev = _context26.next) { | ||
switch (_context27.prev = _context27.next) { | ||
case 0: | ||
@@ -937,4 +975,4 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context26.prev = 5; | ||
_context26.next = 8; | ||
_context27.prev = 5; | ||
_context27.next = 8; | ||
return _AccountsClient2.default.refreshSession(); | ||
@@ -946,5 +984,5 @@ | ||
case 11: | ||
_context26.prev = 11; | ||
_context26.t0 = _context26['catch'](5); | ||
message = _context26.t0.message; | ||
_context27.prev = 11; | ||
_context27.t0 = _context27['catch'](5); | ||
message = _context27.t0.message; | ||
@@ -955,6 +993,6 @@ expect(message).toEqual('falsy token provided'); | ||
case 'end': | ||
return _context26.stop(); | ||
return _context27.stop(); | ||
} | ||
} | ||
}, _callee26, undefined, [[5, 11]]); | ||
}, _callee27, undefined, [[5, 11]]); | ||
}))); | ||
@@ -998,14 +1036,14 @@ // it('requests a new token pair, sets the tokens and the user', async () => { | ||
case 'end': | ||
return _context27.stop(); | ||
return _context28.stop(); | ||
} | ||
} | ||
}, _callee27, undefined); | ||
}, _callee28, undefined); | ||
}))); | ||
describe('verifyEmail', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
switch (_context29.prev = _context29.next) { | ||
case 0: | ||
@@ -1017,4 +1055,4 @@ error = 'something bad'; | ||
} }); | ||
_context28.prev = 2; | ||
_context28.next = 5; | ||
_context29.prev = 2; | ||
_context29.next = 5; | ||
return _AccountsClient2.default.verifyEmail(); | ||
@@ -1026,20 +1064,20 @@ | ||
case 8: | ||
_context28.prev = 8; | ||
_context28.t0 = _context28['catch'](2); | ||
_context29.prev = 8; | ||
_context29.t0 = _context29['catch'](2); | ||
expect(_context28.t0.message).toEqual(error); | ||
expect(_context29.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context28.stop(); | ||
return _context29.stop(); | ||
} | ||
} | ||
}, _callee28, undefined, [[2, 8]]); | ||
}, _callee29, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
switch (_context30.prev = _context30.next) { | ||
case 0: | ||
@@ -1051,3 +1089,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { verifyEmail: mock }); | ||
_context29.next = 4; | ||
_context30.next = 4; | ||
return _AccountsClient2.default.verifyEmail('token'); | ||
@@ -1061,6 +1099,6 @@ | ||
case 'end': | ||
return _context29.stop(); | ||
return _context30.stop(); | ||
} | ||
} | ||
}, _callee29, undefined); | ||
}, _callee30, undefined); | ||
}))); | ||
@@ -1070,7 +1108,7 @@ }); | ||
describe('resetPassword', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
while (1) { | ||
switch (_context30.prev = _context30.next) { | ||
switch (_context31.prev = _context31.next) { | ||
case 0: | ||
@@ -1082,4 +1120,4 @@ error = 'something bad'; | ||
} }); | ||
_context30.prev = 2; | ||
_context30.next = 5; | ||
_context31.prev = 2; | ||
_context31.next = 5; | ||
return _AccountsClient2.default.resetPassword(); | ||
@@ -1091,20 +1129,20 @@ | ||
case 8: | ||
_context30.prev = 8; | ||
_context30.t0 = _context30['catch'](2); | ||
_context31.prev = 8; | ||
_context31.t0 = _context31['catch'](2); | ||
expect(_context30.t0.message).toEqual(error); | ||
expect(_context31.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context30.stop(); | ||
return _context31.stop(); | ||
} | ||
} | ||
}, _callee30, undefined, [[2, 8]]); | ||
}, _callee31, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
while (1) { | ||
switch (_context31.prev = _context31.next) { | ||
switch (_context32.prev = _context32.next) { | ||
case 0: | ||
@@ -1116,3 +1154,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { resetPassword: mock }); | ||
_context31.next = 4; | ||
_context32.next = 4; | ||
return _AccountsClient2.default.resetPassword('token', 'newPassword'); | ||
@@ -1127,6 +1165,6 @@ | ||
case 'end': | ||
return _context31.stop(); | ||
return _context32.stop(); | ||
} | ||
} | ||
}, _callee31, undefined); | ||
}, _callee32, undefined); | ||
}))); | ||
@@ -1136,7 +1174,7 @@ }); | ||
describe('requestPasswordReset', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
while (1) { | ||
switch (_context32.prev = _context32.next) { | ||
switch (_context33.prev = _context33.next) { | ||
case 0: | ||
@@ -1148,5 +1186,5 @@ error = 'something bad'; | ||
} }); | ||
_context32.prev = 2; | ||
_context32.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset(); | ||
_context33.prev = 2; | ||
_context33.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset('email@g.co'); | ||
@@ -1157,20 +1195,20 @@ case 5: | ||
case 8: | ||
_context32.prev = 8; | ||
_context32.t0 = _context32['catch'](2); | ||
_context33.prev = 8; | ||
_context33.t0 = _context33['catch'](2); | ||
expect(_context32.t0.message).toEqual(error); | ||
expect(_context33.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context32.stop(); | ||
return _context33.stop(); | ||
} | ||
} | ||
}, _callee32, undefined, [[2, 8]]); | ||
}, _callee33, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
while (1) { | ||
switch (_context33.prev = _context33.next) { | ||
switch (_context34.prev = _context34.next) { | ||
case 0: | ||
@@ -1182,24 +1220,55 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock }); | ||
_context33.next = 4; | ||
return _AccountsClient2.default.requestPasswordReset('email'); | ||
_context34.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 _context34.stop(); | ||
} | ||
} | ||
}, _callee33, undefined); | ||
}, _callee34, undefined); | ||
}))); | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
while (1) { | ||
switch (_context35.prev = _context35.next) { | ||
case 0: | ||
mock = jest.fn(); | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock }); | ||
_context35.prev = 2; | ||
_context35.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset('email'); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context35.prev = 8; | ||
_context35.t0 = _context35['catch'](2); | ||
expect(_context35.t0.message).toEqual('Valid email must be provided'); | ||
expect(mock.mock.calls.length).toEqual(0); | ||
case 12: | ||
case 'end': | ||
return _context35.stop(); | ||
} | ||
} | ||
}, _callee35, 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 _callee36() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
return regeneratorRuntime.wrap(function _callee36$(_context36) { | ||
while (1) { | ||
switch (_context34.prev = _context34.next) { | ||
switch (_context36.prev = _context36.next) { | ||
case 0: | ||
@@ -1211,5 +1280,5 @@ error = 'something bad'; | ||
} }); | ||
_context34.prev = 2; | ||
_context34.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail(); | ||
_context36.prev = 2; | ||
_context36.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail('email@g.co'); | ||
@@ -1220,20 +1289,20 @@ case 5: | ||
case 8: | ||
_context34.prev = 8; | ||
_context34.t0 = _context34['catch'](2); | ||
_context36.prev = 8; | ||
_context36.t0 = _context36['catch'](2); | ||
expect(_context34.t0.message).toEqual(error); | ||
expect(_context36.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context34.stop(); | ||
return _context36.stop(); | ||
} | ||
} | ||
}, _callee34, undefined, [[2, 8]]); | ||
}, _callee36, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
return regeneratorRuntime.wrap(function _callee37$(_context37) { | ||
while (1) { | ||
switch (_context35.prev = _context35.next) { | ||
switch (_context37.prev = _context37.next) { | ||
case 0: | ||
@@ -1245,17 +1314,48 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: mock }); | ||
_context35.next = 4; | ||
return _AccountsClient2.default.requestVerificationEmail('email'); | ||
_context37.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 _context37.stop(); | ||
} | ||
} | ||
}, _callee35, undefined); | ||
}, _callee37, undefined); | ||
}))); | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee38$(_context38) { | ||
while (1) { | ||
switch (_context38.prev = _context38.next) { | ||
case 0: | ||
mock = jest.fn(); | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: mock }); | ||
_context38.prev = 2; | ||
_context38.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail('email'); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context38.prev = 8; | ||
_context38.t0 = _context38['catch'](2); | ||
expect(_context38.t0.message).toEqual('Valid email must be provided'); | ||
expect(mock.mock.calls.length).toEqual(0); | ||
case 12: | ||
case 'end': | ||
return _context38.stop(); | ||
} | ||
} | ||
}, _callee38, 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); |
194
lib/index.js
(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("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", "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("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["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__) { | ||
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 | ||
@@ -408,3 +411,3 @@ }); | ||
if (!(accessToken && refreshToken)) { | ||
_context7.next = 30; | ||
_context7.next = 33; | ||
break; | ||
@@ -414,2 +417,4 @@ } | ||
_context7.prev = 6; | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken); | ||
@@ -420,3 +425,3 @@ currentTime = Date.now() / 1000; | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context7.next = 14; | ||
_context7.next = 15; | ||
break; | ||
@@ -427,26 +432,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(); | ||
@@ -456,7 +465,7 @@ this.clearUser(); | ||
case 28: | ||
_context7.next = 33; | ||
case 31: | ||
_context7.next = 36; | ||
break; | ||
case 30: | ||
case 33: | ||
this.clearTokens(); | ||
@@ -466,3 +475,3 @@ this.clearUser(); | ||
case 33: | ||
case 36: | ||
case 'end': | ||
@@ -472,3 +481,3 @@ return _context7.stop(); | ||
} | ||
}, _callee7, this, [[6, 23]]); | ||
}, _callee7, this, [[6, 25]]); | ||
})); | ||
@@ -562,3 +571,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) { | ||
@@ -587,16 +596,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)) { | ||
@@ -608,4 +624,4 @@ callback(null, res); | ||
case 19: | ||
_context9.prev = 19; | ||
case 21: | ||
_context9.prev = 21; | ||
_context9.t0 = _context9['catch'](5); | ||
@@ -619,3 +635,3 @@ | ||
case 24: | ||
case 26: | ||
case 'end': | ||
@@ -625,3 +641,3 @@ return _context9.stop(); | ||
} | ||
}, _callee9, this, [[5, 19]]); | ||
}, _callee9, this, [[5, 21]]); | ||
})); | ||
@@ -678,3 +694,6 @@ | ||
} | ||
this.options.onSignedOutHook(); | ||
if (this.options.onSignedOutHook) { | ||
this.options.onSignedOutHook(); | ||
} | ||
_context10.next = 18; | ||
@@ -784,16 +803,24 @@ break; | ||
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': | ||
@@ -803,3 +830,3 @@ return _context13.stop(); | ||
} | ||
}, _callee13, this, [[0, 5]]); | ||
}, _callee13, this, [[2, 7]]); | ||
})); | ||
@@ -821,16 +848,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': | ||
@@ -840,3 +875,3 @@ return _context14.stop(); | ||
} | ||
}, _callee14, this, [[0, 5]]); | ||
}, _callee14, this, [[2, 7]]); | ||
})); | ||
@@ -1025,15 +1060,15 @@ | ||
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 || '/'); | ||
}, | ||
@@ -1059,2 +1094,3 @@ loginOnSignUp: true | ||
// $FlowFixMe | ||
exports.default = function (path) { | ||
@@ -1231,2 +1267,42 @@ 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 _cryptoJs = __webpack_require__(21); | ||
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) { | ||
var cryptoAlgoKey = mapHashConstant[algorithm]; | ||
var cryptoFunction = _cryptoJs2.default[cryptoAlgoKey]; | ||
return cryptoFunction(password).toString(); | ||
}; | ||
/***/ }, | ||
/* 21 */ | ||
/***/ function(module, exports) { | ||
module.exports = require("crypto-js"); | ||
/***/ } | ||
@@ -1233,0 +1309,0 @@ /******/ ]) |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.9", | ||
"version": "0.0.10-alpha.b575b352", | ||
"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", | ||
@@ -73,3 +75,4 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"dependencies": { | ||
"@accounts/common": "^0.0.9", | ||
"@accounts/common": "^0.0.10-alpha.b575b352", | ||
"crypto-js": "^3.1.9-1", | ||
"immutable": "^3.8.1", | ||
@@ -76,0 +79,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
315896
48
5982
0
7
+ Addedcrypto-js@^3.1.9-1
+ Added@accounts/common@0.0.10(transitive)
+ Addedcrypto-js@3.3.0(transitive)
- Removed@accounts/common@0.0.9(transitive)