@accounts/client
Advanced tools
Comparing version 0.0.12-alpha.5e7e66f0 to 0.0.12-alpha.867eb639
@@ -48,2 +48,4 @@ 'use strict'; | ||
var REFRESH_TOKEN = 'accounts:refreshToken'; | ||
var ORIGINAL_ACCESS_TOKEN = 'accounts:originalAccessToken'; | ||
var ORIGINAL_REFRESH_TOKEN = 'accounts:originalRefreshToken'; | ||
@@ -172,10 +174,30 @@ var getTokenKey = function getTokenKey(type, options) { | ||
_context4.t0 = _context4.sent; | ||
_context4.next = 5; | ||
if (_context4.t0) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
_context4.t0 = null; | ||
case 5: | ||
_context4.t1 = _context4.t0; | ||
_context4.next = 8; | ||
return this.getStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 5: | ||
_context4.t1 = _context4.sent; | ||
case 8: | ||
_context4.t2 = _context4.sent; | ||
if (_context4.t2) { | ||
_context4.next = 11; | ||
break; | ||
} | ||
_context4.t2 = null; | ||
case 11: | ||
_context4.t3 = _context4.t2; | ||
tokens = { | ||
accessToken: _context4.t0, | ||
refreshToken: _context4.t1 | ||
accessToken: _context4.t1, | ||
refreshToken: _context4.t3 | ||
}; | ||
@@ -185,3 +207,3 @@ | ||
case 8: | ||
case 14: | ||
case 'end': | ||
@@ -201,2 +223,62 @@ return _context4.stop(); | ||
}, { | ||
key: 'loadOriginalTokensFromStorage', | ||
value: function () { | ||
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
var tokens; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return this.getStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context5.t0 = _context5.sent; | ||
if (_context5.t0) { | ||
_context5.next = 5; | ||
break; | ||
} | ||
_context5.t0 = null; | ||
case 5: | ||
_context5.t1 = _context5.t0; | ||
_context5.next = 8; | ||
return this.getStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options)); | ||
case 8: | ||
_context5.t2 = _context5.sent; | ||
if (_context5.t2) { | ||
_context5.next = 11; | ||
break; | ||
} | ||
_context5.t2 = null; | ||
case 11: | ||
_context5.t3 = _context5.t2; | ||
tokens = { | ||
accessToken: _context5.t1, | ||
refreshToken: _context5.t3 | ||
}; | ||
this.store.dispatch((0, _module.setOriginalTokens)(tokens)); | ||
case 14: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function loadOriginalTokensFromStorage() { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return loadOriginalTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'user', | ||
@@ -211,11 +293,11 @@ value: function user() { | ||
value: function () { | ||
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(username) { | ||
var _ref6, accessToken, refreshToken, res; | ||
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(username) { | ||
var _ref7, accessToken, refreshToken, res, persistImpersonation; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
if ((0, _lodash.isString)(username)) { | ||
_context5.next = 2; | ||
_context6.next = 2; | ||
break; | ||
@@ -228,3 +310,3 @@ } | ||
if (!this.isImpersonated()) { | ||
_context5.next = 4; | ||
_context6.next = 4; | ||
break; | ||
@@ -236,12 +318,12 @@ } | ||
case 4: | ||
_context5.next = 6; | ||
_context6.next = 6; | ||
return this.tokens(); | ||
case 6: | ||
_ref6 = _context5.sent; | ||
accessToken = _ref6.accessToken; | ||
refreshToken = _ref6.refreshToken; | ||
_ref7 = _context6.sent; | ||
accessToken = _ref7.accessToken; | ||
refreshToken = _ref7.refreshToken; | ||
if (accessToken) { | ||
_context5.next = 11; | ||
_context6.next = 11; | ||
break; | ||
@@ -253,10 +335,10 @@ } | ||
case 11: | ||
_context5.next = 13; | ||
_context6.next = 13; | ||
return this.transport.impersonate(accessToken, username); | ||
case 13: | ||
res = _context5.sent; | ||
res = _context6.sent; | ||
if (res.authorized) { | ||
_context5.next = 18; | ||
_context6.next = 18; | ||
break; | ||
@@ -268,22 +350,35 @@ } | ||
case 18: | ||
persistImpersonation = this.options.persistImpersonation; | ||
this.store.dispatch((0, _module.setImpersonated)(true)); | ||
this.store.dispatch((0, _module.setOriginalTokens)({ accessToken: accessToken, refreshToken: refreshToken })); | ||
_context5.next = 22; | ||
if (!persistImpersonation) { | ||
_context6.next = 26; | ||
break; | ||
} | ||
_context6.next = 24; | ||
return this.storeOriginalTokens({ accessToken: accessToken, refreshToken: refreshToken }); | ||
case 24: | ||
_context6.next = 26; | ||
return this.storeTokens(res.tokens); | ||
case 22: | ||
case 26: | ||
this.store.dispatch((0, _module.setTokens)(res.tokens)); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
return _context5.abrupt('return', res); | ||
return _context6.abrupt('return', res); | ||
case 25: | ||
case 29: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee6, this); | ||
})); | ||
function impersonate(_x5) { | ||
return _ref5.apply(this, arguments); | ||
return _ref6.apply(this, arguments); | ||
} | ||
@@ -296,9 +391,9 @@ | ||
value: function () { | ||
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6() { | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
var _ref8 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
if (!this.isImpersonated()) { | ||
_context6.next = 6; | ||
_context7.next = 6; | ||
break; | ||
@@ -310,3 +405,3 @@ } | ||
this.store.dispatch((0, _module.setImpersonated)(false)); | ||
_context6.next = 6; | ||
_context7.next = 6; | ||
return this.refreshSession(); | ||
@@ -316,10 +411,10 @@ | ||
case 'end': | ||
return _context6.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
}, _callee7, this); | ||
})); | ||
function stopImpersonation() { | ||
return _ref7.apply(this, arguments); | ||
return _ref8.apply(this, arguments); | ||
} | ||
@@ -357,13 +452,13 @@ | ||
value: function () { | ||
var _ref8 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8() { | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
this.store.dispatch((0, _module.clearTokens)()); | ||
_context7.next = 3; | ||
_context8.next = 3; | ||
return this.removeStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 3: | ||
_context7.next = 5; | ||
_context8.next = 5; | ||
return this.removeStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
@@ -373,10 +468,10 @@ | ||
case 'end': | ||
return _context7.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee7, this); | ||
}, _callee8, this); | ||
})); | ||
function clearTokens() { | ||
return _ref8.apply(this, arguments); | ||
return _ref9.apply(this, arguments); | ||
} | ||
@@ -389,10 +484,10 @@ | ||
value: function () { | ||
var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8(tokens) { | ||
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(tokens) { | ||
var newAccessToken, newRefreshToken; | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
break; | ||
@@ -404,7 +499,7 @@ } | ||
if (!newAccessToken) { | ||
_context8.next = 5; | ||
_context9.next = 5; | ||
break; | ||
} | ||
_context8.next = 5; | ||
_context9.next = 5; | ||
return this.setStorageData(getTokenKey(ACCESS_TOKEN, this.options), newAccessToken); | ||
@@ -416,7 +511,7 @@ | ||
if (!newRefreshToken) { | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
break; | ||
} | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
return this.setStorageData(getTokenKey(REFRESH_TOKEN, this.options), newRefreshToken); | ||
@@ -426,10 +521,10 @@ | ||
case 'end': | ||
return _context8.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee8, this); | ||
}, _callee9, this); | ||
})); | ||
function storeTokens(_x6) { | ||
return _ref9.apply(this, arguments); | ||
return _ref10.apply(this, arguments); | ||
} | ||
@@ -440,2 +535,51 @@ | ||
}, { | ||
key: 'storeOriginalTokens', | ||
value: function () { | ||
var _ref11 = _asyncToGenerator(regeneratorRuntime.mark(function _callee10(tokens) { | ||
var originalAccessToken, originalRefreshToken; | ||
return regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
originalAccessToken = tokens.accessToken; | ||
if (!originalAccessToken) { | ||
_context10.next = 5; | ||
break; | ||
} | ||
_context10.next = 5; | ||
return this.setStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options), originalAccessToken); | ||
case 5: | ||
originalRefreshToken = tokens.refreshToken; | ||
if (!originalRefreshToken) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
_context10.next = 9; | ||
return this.setStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options), originalRefreshToken); | ||
case 9: | ||
case 'end': | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee10, this); | ||
})); | ||
function storeOriginalTokens(_x7) { | ||
return _ref11.apply(this, arguments); | ||
} | ||
return storeOriginalTokens; | ||
}() | ||
}, { | ||
key: 'clearUser', | ||
@@ -448,9 +592,9 @@ value: function clearUser() { | ||
value: function () { | ||
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9() { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
var _ref12 = _asyncToGenerator(regeneratorRuntime.mark(function _callee11() { | ||
return regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
_context9.prev = 0; | ||
_context9.next = 3; | ||
_context11.prev = 0; | ||
_context11.next = 3; | ||
return this.refreshSession(); | ||
@@ -462,20 +606,20 @@ | ||
} | ||
_context9.next = 9; | ||
_context11.next = 9; | ||
break; | ||
case 6: | ||
_context9.prev = 6; | ||
_context9.t0 = _context9['catch'](0); | ||
throw _context9.t0; | ||
_context11.prev = 6; | ||
_context11.t0 = _context11['catch'](0); | ||
throw _context11.t0; | ||
case 9: | ||
case 'end': | ||
return _context9.stop(); | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee9, this, [[0, 6]]); | ||
}, _callee11, this, [[0, 6]]); | ||
})); | ||
function resumeSession() { | ||
return _ref10.apply(this, arguments); | ||
return _ref12.apply(this, arguments); | ||
} | ||
@@ -488,23 +632,23 @@ | ||
value: function () { | ||
var _ref11 = _asyncToGenerator(regeneratorRuntime.mark(function _callee10() { | ||
var _ref12, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
var _ref13 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12() { | ||
var _ref14, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
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: | ||
_context10.next = 2; | ||
_context12.next = 2; | ||
return this.tokens(); | ||
case 2: | ||
_ref12 = _context10.sent; | ||
accessToken = _ref12.accessToken; | ||
refreshToken = _ref12.refreshToken; | ||
_ref14 = _context12.sent; | ||
accessToken = _ref14.accessToken; | ||
refreshToken = _ref14.refreshToken; | ||
if (!(accessToken && refreshToken)) { | ||
_context10.next = 33; | ||
_context12.next = 33; | ||
break; | ||
} | ||
_context10.prev = 6; | ||
_context12.prev = 6; | ||
@@ -517,3 +661,3 @@ this.store.dispatch((0, _module.loggingIn)(true)); | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context10.next = 15; | ||
_context12.next = 15; | ||
break; | ||
@@ -524,15 +668,15 @@ } | ||
this.clearUser(); | ||
_context10.next = 23; | ||
_context12.next = 23; | ||
break; | ||
case 15: | ||
_context10.next = 17; | ||
_context12.next = 17; | ||
return this.transport.refreshTokens(accessToken, refreshToken); | ||
case 17: | ||
refreshedSession = _context10.sent; | ||
refreshedSession = _context12.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context10.next = 21; | ||
_context12.next = 21; | ||
return this.storeTokens(refreshedSession.tokens); | ||
@@ -545,8 +689,8 @@ | ||
case 23: | ||
_context10.next = 31; | ||
_context12.next = 31; | ||
break; | ||
case 25: | ||
_context10.prev = 25; | ||
_context10.t0 = _context10['catch'](6); | ||
_context12.prev = 25; | ||
_context12.t0 = _context12['catch'](6); | ||
@@ -559,3 +703,3 @@ this.store.dispatch((0, _module.loggingIn)(false)); | ||
case 31: | ||
_context10.next = 36; | ||
_context12.next = 36; | ||
break; | ||
@@ -570,10 +714,10 @@ | ||
case 'end': | ||
return _context10.stop(); | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee10, this, [[6, 25]]); | ||
}, _callee12, this, [[6, 25]]); | ||
})); | ||
function refreshSession() { | ||
return _ref11.apply(this, arguments); | ||
return _ref13.apply(this, arguments); | ||
} | ||
@@ -586,10 +730,10 @@ | ||
value: function () { | ||
var _ref13 = _asyncToGenerator(regeneratorRuntime.mark(function _callee11(user, callback) { | ||
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(user, callback) { | ||
var hashAlgorithm, password, userToCreate, userId, onUserCreated; | ||
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: | ||
if (!(!user || user.password === undefined)) { | ||
_context11.next = 2; | ||
_context13.next = 2; | ||
break; | ||
@@ -605,3 +749,3 @@ } | ||
if (!(!user.password || (0, _lodash.isString)(user.password) && !_common.validators.validatePassword(user.password))) { | ||
_context11.next = 4; | ||
_context13.next = 4; | ||
break; | ||
@@ -614,3 +758,3 @@ } | ||
if (!(!_common.validators.validateUsername(user.username) && !_common.validators.validateEmail(user.email))) { | ||
_context11.next = 6; | ||
_context13.next = 6; | ||
break; | ||
@@ -625,8 +769,8 @@ } | ||
userToCreate = _extends({}, user, { password: password }); | ||
_context11.prev = 9; | ||
_context11.next = 12; | ||
_context13.prev = 9; | ||
_context13.next = 12; | ||
return this.transport.createUser(userToCreate); | ||
case 12: | ||
userId = _context11.sent; | ||
userId = _context13.sent; | ||
onUserCreated = this.options.onUserCreated; | ||
@@ -639,47 +783,47 @@ | ||
if (!(0, _lodash.isFunction)(onUserCreated)) { | ||
_context11.next = 24; | ||
_context13.next = 24; | ||
break; | ||
} | ||
_context11.prev = 16; | ||
_context11.next = 19; | ||
_context13.prev = 16; | ||
_context13.next = 19; | ||
return onUserCreated({ id: userId }); | ||
case 19: | ||
_context11.next = 24; | ||
_context13.next = 24; | ||
break; | ||
case 21: | ||
_context11.prev = 21; | ||
_context11.t0 = _context11['catch'](16); | ||
_context13.prev = 21; | ||
_context13.t0 = _context13['catch'](16); | ||
console.log(_context11.t0); | ||
console.log(_context13.t0); | ||
case 24: | ||
_context11.next = 26; | ||
_context13.next = 26; | ||
return this.loginWithPassword({ id: userId }, user.password); | ||
case 26: | ||
_context11.next = 32; | ||
_context13.next = 32; | ||
break; | ||
case 28: | ||
_context11.prev = 28; | ||
_context11.t1 = _context11['catch'](9); | ||
_context13.prev = 28; | ||
_context13.t1 = _context13['catch'](9); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context11.t1); | ||
callback(_context13.t1); | ||
} | ||
throw new _common.AccountsError(_context11.t1.message); | ||
throw new _common.AccountsError(_context13.t1.message); | ||
case 32: | ||
case 'end': | ||
return _context11.stop(); | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee11, this, [[9, 28], [16, 21]]); | ||
}, _callee13, this, [[9, 28], [16, 21]]); | ||
})); | ||
function createUser(_x7, _x8) { | ||
return _ref13.apply(this, arguments); | ||
function createUser(_x8, _x9) { | ||
return _ref15.apply(this, arguments); | ||
} | ||
@@ -692,10 +836,10 @@ | ||
value: function () { | ||
var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12(user, password, callback) { | ||
var _ref16 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(user, password, callback) { | ||
var hashAlgorithm, pass, res; | ||
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: | ||
if (!(!password || !user)) { | ||
_context12.next = 2; | ||
_context14.next = 2; | ||
break; | ||
@@ -708,3 +852,3 @@ } | ||
if (!(!(0, _lodash.isString)(user) && !isValidUserObject(user) || !(0, _lodash.isString)(password))) { | ||
_context12.next = 4; | ||
_context14.next = 4; | ||
break; | ||
@@ -718,14 +862,14 @@ } | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
_context12.prev = 5; | ||
_context14.prev = 5; | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password; | ||
_context12.next = 10; | ||
_context14.next = 10; | ||
return this.transport.loginWithPassword(user, pass); | ||
case 10: | ||
res = _context12.sent; | ||
res = _context14.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context12.next = 14; | ||
_context14.next = 14; | ||
return this.storeTokens(res.tokens); | ||
@@ -745,24 +889,24 @@ | ||
return _context12.abrupt('return', res); | ||
return _context14.abrupt('return', res); | ||
case 21: | ||
_context12.prev = 21; | ||
_context12.t0 = _context12['catch'](5); | ||
_context14.prev = 21; | ||
_context14.t0 = _context14['catch'](5); | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context12.t0, null); | ||
callback(_context14.t0, null); | ||
} | ||
throw new _common.AccountsError(_context12.t0.message); | ||
throw new _common.AccountsError(_context14.t0.message); | ||
case 26: | ||
case 'end': | ||
return _context12.stop(); | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee12, this, [[5, 21]]); | ||
}, _callee14, this, [[5, 21]]); | ||
})); | ||
function loginWithPassword(_x9, _x10, _x11) { | ||
return _ref14.apply(this, arguments); | ||
function loginWithPassword(_x10, _x11, _x12) { | ||
return _ref16.apply(this, arguments); | ||
} | ||
@@ -785,23 +929,23 @@ | ||
value: function () { | ||
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(callback) { | ||
var _ref16, accessToken; | ||
var _ref17 = _asyncToGenerator(regeneratorRuntime.mark(function _callee15(callback) { | ||
var _ref18, accessToken; | ||
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: | ||
_context13.prev = 0; | ||
_context13.next = 3; | ||
_context15.prev = 0; | ||
_context15.next = 3; | ||
return this.tokens(); | ||
case 3: | ||
_ref16 = _context13.sent; | ||
accessToken = _ref16.accessToken; | ||
_ref18 = _context15.sent; | ||
accessToken = _ref18.accessToken; | ||
if (!accessToken) { | ||
_context13.next = 8; | ||
_context15.next = 8; | ||
break; | ||
} | ||
_context13.next = 8; | ||
_context15.next = 8; | ||
return this.transport.logout(accessToken); | ||
@@ -820,8 +964,8 @@ | ||
} | ||
_context13.next = 20; | ||
_context15.next = 20; | ||
break; | ||
case 14: | ||
_context13.prev = 14; | ||
_context13.t0 = _context13['catch'](0); | ||
_context15.prev = 14; | ||
_context15.t0 = _context15['catch'](0); | ||
@@ -831,16 +975,16 @@ this.clearTokens(); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context13.t0); | ||
callback(_context15.t0); | ||
} | ||
throw new _common.AccountsError(_context13.t0.message); | ||
throw new _common.AccountsError(_context15.t0.message); | ||
case 20: | ||
case 'end': | ||
return _context13.stop(); | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee13, this, [[0, 14]]); | ||
}, _callee15, this, [[0, 14]]); | ||
})); | ||
function logout(_x12) { | ||
return _ref15.apply(this, arguments); | ||
function logout(_x13) { | ||
return _ref17.apply(this, arguments); | ||
} | ||
@@ -853,30 +997,30 @@ | ||
value: function () { | ||
var _ref17 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(token) { | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
var _ref19 = _asyncToGenerator(regeneratorRuntime.mark(function _callee16(token) { | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
_context14.prev = 0; | ||
_context14.next = 3; | ||
_context16.prev = 0; | ||
_context16.next = 3; | ||
return this.transport.verifyEmail(token); | ||
case 3: | ||
_context14.next = 8; | ||
_context16.next = 8; | ||
break; | ||
case 5: | ||
_context14.prev = 5; | ||
_context14.t0 = _context14['catch'](0); | ||
throw new _common.AccountsError(_context14.t0.message); | ||
_context16.prev = 5; | ||
_context16.t0 = _context16['catch'](0); | ||
throw new _common.AccountsError(_context16.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context14.stop(); | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee14, this, [[0, 5]]); | ||
}, _callee16, this, [[0, 5]]); | ||
})); | ||
function verifyEmail(_x13) { | ||
return _ref17.apply(this, arguments); | ||
function verifyEmail(_x14) { | ||
return _ref19.apply(this, arguments); | ||
} | ||
@@ -889,10 +1033,10 @@ | ||
value: function () { | ||
var _ref18 = _asyncToGenerator(regeneratorRuntime.mark(function _callee15(token, newPassword) { | ||
var _ref20 = _asyncToGenerator(regeneratorRuntime.mark(function _callee17(token, newPassword) { | ||
var hashAlgorithm, password; | ||
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: | ||
if (_common.validators.validatePassword(newPassword)) { | ||
_context15.next = 2; | ||
_context17.next = 2; | ||
break; | ||
@@ -906,25 +1050,25 @@ } | ||
password = hashAlgorithm ? (0, _encryption.hashPassword)(newPassword, hashAlgorithm) : newPassword; | ||
_context15.prev = 4; | ||
_context15.next = 7; | ||
_context17.prev = 4; | ||
_context17.next = 7; | ||
return this.transport.resetPassword(token, password); | ||
case 7: | ||
_context15.next = 12; | ||
_context17.next = 12; | ||
break; | ||
case 9: | ||
_context15.prev = 9; | ||
_context15.t0 = _context15['catch'](4); | ||
throw new _common.AccountsError(_context15.t0.message); | ||
_context17.prev = 9; | ||
_context17.t0 = _context17['catch'](4); | ||
throw new _common.AccountsError(_context17.t0.message); | ||
case 12: | ||
case 'end': | ||
return _context15.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee15, this, [[4, 9]]); | ||
}, _callee17, this, [[4, 9]]); | ||
})); | ||
function resetPassword(_x14, _x15) { | ||
return _ref18.apply(this, arguments); | ||
function resetPassword(_x15, _x16) { | ||
return _ref20.apply(this, arguments); | ||
} | ||
@@ -937,9 +1081,9 @@ | ||
value: function () { | ||
var _ref19 = _asyncToGenerator(regeneratorRuntime.mark(function _callee16(email) { | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
var _ref21 = _asyncToGenerator(regeneratorRuntime.mark(function _callee18(email) { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context16.next = 2; | ||
_context18.next = 2; | ||
break; | ||
@@ -951,25 +1095,25 @@ } | ||
case 2: | ||
_context16.prev = 2; | ||
_context16.next = 5; | ||
_context18.prev = 2; | ||
_context18.next = 5; | ||
return this.transport.sendResetPasswordEmail(email); | ||
case 5: | ||
_context16.next = 10; | ||
_context18.next = 10; | ||
break; | ||
case 7: | ||
_context16.prev = 7; | ||
_context16.t0 = _context16['catch'](2); | ||
throw new _common.AccountsError(_context16.t0.message); | ||
_context18.prev = 7; | ||
_context18.t0 = _context18['catch'](2); | ||
throw new _common.AccountsError(_context18.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context16.stop(); | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee16, this, [[2, 7]]); | ||
}, _callee18, this, [[2, 7]]); | ||
})); | ||
function requestPasswordReset(_x16) { | ||
return _ref19.apply(this, arguments); | ||
function requestPasswordReset(_x17) { | ||
return _ref21.apply(this, arguments); | ||
} | ||
@@ -982,9 +1126,9 @@ | ||
value: function () { | ||
var _ref20 = _asyncToGenerator(regeneratorRuntime.mark(function _callee17(email) { | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
var _ref22 = _asyncToGenerator(regeneratorRuntime.mark(function _callee19(email) { | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context17.next = 2; | ||
_context19.next = 2; | ||
break; | ||
@@ -996,25 +1140,25 @@ } | ||
case 2: | ||
_context17.prev = 2; | ||
_context17.next = 5; | ||
_context19.prev = 2; | ||
_context19.next = 5; | ||
return this.transport.sendVerificationEmail(email); | ||
case 5: | ||
_context17.next = 10; | ||
_context19.next = 10; | ||
break; | ||
case 7: | ||
_context17.prev = 7; | ||
_context17.t0 = _context17['catch'](2); | ||
throw new _common.AccountsError(_context17.t0.message); | ||
_context19.prev = 7; | ||
_context19.t0 = _context19['catch'](2); | ||
throw new _common.AccountsError(_context19.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context17.stop(); | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee17, this, [[2, 7]]); | ||
}, _callee19, this, [[2, 7]]); | ||
})); | ||
function requestVerificationEmail(_x17) { | ||
return _ref20.apply(this, arguments); | ||
function requestVerificationEmail(_x18) { | ||
return _ref22.apply(this, arguments); | ||
} | ||
@@ -1035,19 +1179,25 @@ | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
_this.instance = new AccountsClient(_extends({}, _config3.default, options), transport); | ||
return _context18.abrupt('return', _this.instance.loadTokensFromStorage().then(function () { | ||
return _this.instance; | ||
})); | ||
_context20.next = 3; | ||
return _this.instance.loadTokensFromStorage(); | ||
case 2: | ||
case 3: | ||
_context20.next = 5; | ||
return _this.instance.loadOriginalTokensFromStorage(); | ||
case 5: | ||
return _context20.abrupt('return', _this.instance); | ||
case 6: | ||
case 'end': | ||
return _context18.stop(); | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee18, _this); | ||
}, _callee20, _this); | ||
}))(); | ||
@@ -1054,0 +1204,0 @@ }, |
@@ -59,3 +59,4 @@ 'use strict'; | ||
}, | ||
loginOnSignUp: true | ||
loginOnSignUp: true, | ||
persistImpersonation: true | ||
}); |
583
lib/index.js
@@ -152,2 +152,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var REFRESH_TOKEN = 'accounts:refreshToken'; | ||
var ORIGINAL_ACCESS_TOKEN = 'accounts:originalAccessToken'; | ||
var ORIGINAL_REFRESH_TOKEN = 'accounts:originalRefreshToken'; | ||
@@ -276,10 +278,30 @@ var getTokenKey = function getTokenKey(type, options) { | ||
_context4.t0 = _context4.sent; | ||
_context4.next = 5; | ||
if (_context4.t0) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
_context4.t0 = null; | ||
case 5: | ||
_context4.t1 = _context4.t0; | ||
_context4.next = 8; | ||
return this.getStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 5: | ||
_context4.t1 = _context4.sent; | ||
case 8: | ||
_context4.t2 = _context4.sent; | ||
if (_context4.t2) { | ||
_context4.next = 11; | ||
break; | ||
} | ||
_context4.t2 = null; | ||
case 11: | ||
_context4.t3 = _context4.t2; | ||
tokens = { | ||
accessToken: _context4.t0, | ||
refreshToken: _context4.t1 | ||
accessToken: _context4.t1, | ||
refreshToken: _context4.t3 | ||
}; | ||
@@ -289,3 +311,3 @@ | ||
case 8: | ||
case 14: | ||
case 'end': | ||
@@ -305,2 +327,62 @@ return _context4.stop(); | ||
}, { | ||
key: 'loadOriginalTokensFromStorage', | ||
value: function () { | ||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5() { | ||
var tokens; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return this.getStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context5.t0 = _context5.sent; | ||
if (_context5.t0) { | ||
_context5.next = 5; | ||
break; | ||
} | ||
_context5.t0 = null; | ||
case 5: | ||
_context5.t1 = _context5.t0; | ||
_context5.next = 8; | ||
return this.getStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options)); | ||
case 8: | ||
_context5.t2 = _context5.sent; | ||
if (_context5.t2) { | ||
_context5.next = 11; | ||
break; | ||
} | ||
_context5.t2 = null; | ||
case 11: | ||
_context5.t3 = _context5.t2; | ||
tokens = { | ||
accessToken: _context5.t1, | ||
refreshToken: _context5.t3 | ||
}; | ||
this.store.dispatch((0, _module.setOriginalTokens)(tokens)); | ||
case 14: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function loadOriginalTokensFromStorage() { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return loadOriginalTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'user', | ||
@@ -315,11 +397,11 @@ value: function user() { | ||
value: function () { | ||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(username) { | ||
var _ref6, accessToken, refreshToken, res; | ||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(username) { | ||
var _ref7, accessToken, refreshToken, res, persistImpersonation; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
if ((0, _lodash.isString)(username)) { | ||
_context5.next = 2; | ||
_context6.next = 2; | ||
break; | ||
@@ -332,3 +414,3 @@ } | ||
if (!this.isImpersonated()) { | ||
_context5.next = 4; | ||
_context6.next = 4; | ||
break; | ||
@@ -340,12 +422,12 @@ } | ||
case 4: | ||
_context5.next = 6; | ||
_context6.next = 6; | ||
return this.tokens(); | ||
case 6: | ||
_ref6 = _context5.sent; | ||
accessToken = _ref6.accessToken; | ||
refreshToken = _ref6.refreshToken; | ||
_ref7 = _context6.sent; | ||
accessToken = _ref7.accessToken; | ||
refreshToken = _ref7.refreshToken; | ||
if (accessToken) { | ||
_context5.next = 11; | ||
_context6.next = 11; | ||
break; | ||
@@ -357,10 +439,10 @@ } | ||
case 11: | ||
_context5.next = 13; | ||
_context6.next = 13; | ||
return this.transport.impersonate(accessToken, username); | ||
case 13: | ||
res = _context5.sent; | ||
res = _context6.sent; | ||
if (res.authorized) { | ||
_context5.next = 18; | ||
_context6.next = 18; | ||
break; | ||
@@ -372,22 +454,35 @@ } | ||
case 18: | ||
persistImpersonation = this.options.persistImpersonation; | ||
this.store.dispatch((0, _module.setImpersonated)(true)); | ||
this.store.dispatch((0, _module.setOriginalTokens)({ accessToken: accessToken, refreshToken: refreshToken })); | ||
_context5.next = 22; | ||
if (!persistImpersonation) { | ||
_context6.next = 26; | ||
break; | ||
} | ||
_context6.next = 24; | ||
return this.storeOriginalTokens({ accessToken: accessToken, refreshToken: refreshToken }); | ||
case 24: | ||
_context6.next = 26; | ||
return this.storeTokens(res.tokens); | ||
case 22: | ||
case 26: | ||
this.store.dispatch((0, _module.setTokens)(res.tokens)); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
return _context5.abrupt('return', res); | ||
return _context6.abrupt('return', res); | ||
case 25: | ||
case 29: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}, _callee6, this); | ||
})); | ||
function impersonate(_x5) { | ||
return _ref5.apply(this, arguments); | ||
return _ref6.apply(this, arguments); | ||
} | ||
@@ -400,9 +495,9 @@ | ||
value: function () { | ||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6() { | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7() { | ||
return _regenerator2.default.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
if (!this.isImpersonated()) { | ||
_context6.next = 6; | ||
_context7.next = 6; | ||
break; | ||
@@ -414,3 +509,3 @@ } | ||
this.store.dispatch((0, _module.setImpersonated)(false)); | ||
_context6.next = 6; | ||
_context7.next = 6; | ||
return this.refreshSession(); | ||
@@ -420,10 +515,10 @@ | ||
case 'end': | ||
return _context6.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
}, _callee7, this); | ||
})); | ||
function stopImpersonation() { | ||
return _ref7.apply(this, arguments); | ||
return _ref8.apply(this, arguments); | ||
} | ||
@@ -461,13 +556,13 @@ | ||
value: function () { | ||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7() { | ||
return _regenerator2.default.wrap(function _callee7$(_context7) { | ||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8() { | ||
return _regenerator2.default.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
this.store.dispatch((0, _module.clearTokens)()); | ||
_context7.next = 3; | ||
_context8.next = 3; | ||
return this.removeStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 3: | ||
_context7.next = 5; | ||
_context8.next = 5; | ||
return this.removeStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
@@ -477,10 +572,10 @@ | ||
case 'end': | ||
return _context7.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee7, this); | ||
}, _callee8, this); | ||
})); | ||
function clearTokens() { | ||
return _ref8.apply(this, arguments); | ||
return _ref9.apply(this, arguments); | ||
} | ||
@@ -493,10 +588,10 @@ | ||
value: function () { | ||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(tokens) { | ||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(tokens) { | ||
var newAccessToken, newRefreshToken; | ||
return _regenerator2.default.wrap(function _callee8$(_context8) { | ||
return _regenerator2.default.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
break; | ||
@@ -508,7 +603,7 @@ } | ||
if (!newAccessToken) { | ||
_context8.next = 5; | ||
_context9.next = 5; | ||
break; | ||
} | ||
_context8.next = 5; | ||
_context9.next = 5; | ||
return this.setStorageData(getTokenKey(ACCESS_TOKEN, this.options), newAccessToken); | ||
@@ -520,7 +615,7 @@ | ||
if (!newRefreshToken) { | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
break; | ||
} | ||
_context8.next = 9; | ||
_context9.next = 9; | ||
return this.setStorageData(getTokenKey(REFRESH_TOKEN, this.options), newRefreshToken); | ||
@@ -530,10 +625,10 @@ | ||
case 'end': | ||
return _context8.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee8, this); | ||
}, _callee9, this); | ||
})); | ||
function storeTokens(_x6) { | ||
return _ref9.apply(this, arguments); | ||
return _ref10.apply(this, arguments); | ||
} | ||
@@ -544,2 +639,51 @@ | ||
}, { | ||
key: 'storeOriginalTokens', | ||
value: function () { | ||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(tokens) { | ||
var originalAccessToken, originalRefreshToken; | ||
return _regenerator2.default.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
originalAccessToken = tokens.accessToken; | ||
if (!originalAccessToken) { | ||
_context10.next = 5; | ||
break; | ||
} | ||
_context10.next = 5; | ||
return this.setStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options), originalAccessToken); | ||
case 5: | ||
originalRefreshToken = tokens.refreshToken; | ||
if (!originalRefreshToken) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
_context10.next = 9; | ||
return this.setStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options), originalRefreshToken); | ||
case 9: | ||
case 'end': | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee10, this); | ||
})); | ||
function storeOriginalTokens(_x7) { | ||
return _ref11.apply(this, arguments); | ||
} | ||
return storeOriginalTokens; | ||
}() | ||
}, { | ||
key: 'clearUser', | ||
@@ -552,9 +696,9 @@ value: function clearUser() { | ||
value: function () { | ||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9() { | ||
return _regenerator2.default.wrap(function _callee9$(_context9) { | ||
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11() { | ||
return _regenerator2.default.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
_context9.prev = 0; | ||
_context9.next = 3; | ||
_context11.prev = 0; | ||
_context11.next = 3; | ||
return this.refreshSession(); | ||
@@ -566,20 +710,20 @@ | ||
} | ||
_context9.next = 9; | ||
_context11.next = 9; | ||
break; | ||
case 6: | ||
_context9.prev = 6; | ||
_context9.t0 = _context9['catch'](0); | ||
throw _context9.t0; | ||
_context11.prev = 6; | ||
_context11.t0 = _context11['catch'](0); | ||
throw _context11.t0; | ||
case 9: | ||
case 'end': | ||
return _context9.stop(); | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee9, this, [[0, 6]]); | ||
}, _callee11, this, [[0, 6]]); | ||
})); | ||
function resumeSession() { | ||
return _ref10.apply(this, arguments); | ||
return _ref12.apply(this, arguments); | ||
} | ||
@@ -592,23 +736,23 @@ | ||
value: function () { | ||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10() { | ||
var _ref12, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12() { | ||
var _ref14, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
return _regenerator2.default.wrap(function _callee10$(_context10) { | ||
return _regenerator2.default.wrap(function _callee12$(_context12) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
switch (_context12.prev = _context12.next) { | ||
case 0: | ||
_context10.next = 2; | ||
_context12.next = 2; | ||
return this.tokens(); | ||
case 2: | ||
_ref12 = _context10.sent; | ||
accessToken = _ref12.accessToken; | ||
refreshToken = _ref12.refreshToken; | ||
_ref14 = _context12.sent; | ||
accessToken = _ref14.accessToken; | ||
refreshToken = _ref14.refreshToken; | ||
if (!(accessToken && refreshToken)) { | ||
_context10.next = 33; | ||
_context12.next = 33; | ||
break; | ||
} | ||
_context10.prev = 6; | ||
_context12.prev = 6; | ||
@@ -621,3 +765,3 @@ this.store.dispatch((0, _module.loggingIn)(true)); | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context10.next = 15; | ||
_context12.next = 15; | ||
break; | ||
@@ -628,15 +772,15 @@ } | ||
this.clearUser(); | ||
_context10.next = 23; | ||
_context12.next = 23; | ||
break; | ||
case 15: | ||
_context10.next = 17; | ||
_context12.next = 17; | ||
return this.transport.refreshTokens(accessToken, refreshToken); | ||
case 17: | ||
refreshedSession = _context10.sent; | ||
refreshedSession = _context12.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context10.next = 21; | ||
_context12.next = 21; | ||
return this.storeTokens(refreshedSession.tokens); | ||
@@ -649,8 +793,8 @@ | ||
case 23: | ||
_context10.next = 31; | ||
_context12.next = 31; | ||
break; | ||
case 25: | ||
_context10.prev = 25; | ||
_context10.t0 = _context10['catch'](6); | ||
_context12.prev = 25; | ||
_context12.t0 = _context12['catch'](6); | ||
@@ -663,3 +807,3 @@ this.store.dispatch((0, _module.loggingIn)(false)); | ||
case 31: | ||
_context10.next = 36; | ||
_context12.next = 36; | ||
break; | ||
@@ -674,10 +818,10 @@ | ||
case 'end': | ||
return _context10.stop(); | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee10, this, [[6, 25]]); | ||
}, _callee12, this, [[6, 25]]); | ||
})); | ||
function refreshSession() { | ||
return _ref11.apply(this, arguments); | ||
return _ref13.apply(this, arguments); | ||
} | ||
@@ -690,10 +834,10 @@ | ||
value: function () { | ||
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(user, callback) { | ||
var _ref15 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(user, callback) { | ||
var hashAlgorithm, password, userToCreate, userId, onUserCreated; | ||
return _regenerator2.default.wrap(function _callee11$(_context11) { | ||
return _regenerator2.default.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
if (!(!user || user.password === undefined)) { | ||
_context11.next = 2; | ||
_context13.next = 2; | ||
break; | ||
@@ -709,3 +853,3 @@ } | ||
if (!(!user.password || (0, _lodash.isString)(user.password) && !_common.validators.validatePassword(user.password))) { | ||
_context11.next = 4; | ||
_context13.next = 4; | ||
break; | ||
@@ -718,3 +862,3 @@ } | ||
if (!(!_common.validators.validateUsername(user.username) && !_common.validators.validateEmail(user.email))) { | ||
_context11.next = 6; | ||
_context13.next = 6; | ||
break; | ||
@@ -729,8 +873,8 @@ } | ||
userToCreate = (0, _extends3.default)({}, user, { password: password }); | ||
_context11.prev = 9; | ||
_context11.next = 12; | ||
_context13.prev = 9; | ||
_context13.next = 12; | ||
return this.transport.createUser(userToCreate); | ||
case 12: | ||
userId = _context11.sent; | ||
userId = _context13.sent; | ||
onUserCreated = this.options.onUserCreated; | ||
@@ -743,47 +887,47 @@ | ||
if (!(0, _lodash.isFunction)(onUserCreated)) { | ||
_context11.next = 24; | ||
_context13.next = 24; | ||
break; | ||
} | ||
_context11.prev = 16; | ||
_context11.next = 19; | ||
_context13.prev = 16; | ||
_context13.next = 19; | ||
return onUserCreated({ id: userId }); | ||
case 19: | ||
_context11.next = 24; | ||
_context13.next = 24; | ||
break; | ||
case 21: | ||
_context11.prev = 21; | ||
_context11.t0 = _context11['catch'](16); | ||
_context13.prev = 21; | ||
_context13.t0 = _context13['catch'](16); | ||
console.log(_context11.t0); | ||
console.log(_context13.t0); | ||
case 24: | ||
_context11.next = 26; | ||
_context13.next = 26; | ||
return this.loginWithPassword({ id: userId }, user.password); | ||
case 26: | ||
_context11.next = 32; | ||
_context13.next = 32; | ||
break; | ||
case 28: | ||
_context11.prev = 28; | ||
_context11.t1 = _context11['catch'](9); | ||
_context13.prev = 28; | ||
_context13.t1 = _context13['catch'](9); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context11.t1); | ||
callback(_context13.t1); | ||
} | ||
throw new _common.AccountsError(_context11.t1.message); | ||
throw new _common.AccountsError(_context13.t1.message); | ||
case 32: | ||
case 'end': | ||
return _context11.stop(); | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee11, this, [[9, 28], [16, 21]]); | ||
}, _callee13, this, [[9, 28], [16, 21]]); | ||
})); | ||
function createUser(_x7, _x8) { | ||
return _ref13.apply(this, arguments); | ||
function createUser(_x8, _x9) { | ||
return _ref15.apply(this, arguments); | ||
} | ||
@@ -796,10 +940,10 @@ | ||
value: function () { | ||
var _ref14 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(user, password, callback) { | ||
var _ref16 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(user, password, callback) { | ||
var hashAlgorithm, pass, res; | ||
return _regenerator2.default.wrap(function _callee12$(_context12) { | ||
return _regenerator2.default.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context12.prev = _context12.next) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
if (!(!password || !user)) { | ||
_context12.next = 2; | ||
_context14.next = 2; | ||
break; | ||
@@ -812,3 +956,3 @@ } | ||
if (!(!(0, _lodash.isString)(user) && !isValidUserObject(user) || !(0, _lodash.isString)(password))) { | ||
_context12.next = 4; | ||
_context14.next = 4; | ||
break; | ||
@@ -822,14 +966,14 @@ } | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
_context12.prev = 5; | ||
_context14.prev = 5; | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password; | ||
_context12.next = 10; | ||
_context14.next = 10; | ||
return this.transport.loginWithPassword(user, pass); | ||
case 10: | ||
res = _context12.sent; | ||
res = _context14.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context12.next = 14; | ||
_context14.next = 14; | ||
return this.storeTokens(res.tokens); | ||
@@ -849,24 +993,24 @@ | ||
return _context12.abrupt('return', res); | ||
return _context14.abrupt('return', res); | ||
case 21: | ||
_context12.prev = 21; | ||
_context12.t0 = _context12['catch'](5); | ||
_context14.prev = 21; | ||
_context14.t0 = _context14['catch'](5); | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context12.t0, null); | ||
callback(_context14.t0, null); | ||
} | ||
throw new _common.AccountsError(_context12.t0.message); | ||
throw new _common.AccountsError(_context14.t0.message); | ||
case 26: | ||
case 'end': | ||
return _context12.stop(); | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee12, this, [[5, 21]]); | ||
}, _callee14, this, [[5, 21]]); | ||
})); | ||
function loginWithPassword(_x9, _x10, _x11) { | ||
return _ref14.apply(this, arguments); | ||
function loginWithPassword(_x10, _x11, _x12) { | ||
return _ref16.apply(this, arguments); | ||
} | ||
@@ -889,23 +1033,23 @@ | ||
value: function () { | ||
var _ref15 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(callback) { | ||
var _ref16, accessToken; | ||
var _ref17 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15(callback) { | ||
var _ref18, accessToken; | ||
return _regenerator2.default.wrap(function _callee13$(_context13) { | ||
return _regenerator2.default.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
_context13.prev = 0; | ||
_context13.next = 3; | ||
_context15.prev = 0; | ||
_context15.next = 3; | ||
return this.tokens(); | ||
case 3: | ||
_ref16 = _context13.sent; | ||
accessToken = _ref16.accessToken; | ||
_ref18 = _context15.sent; | ||
accessToken = _ref18.accessToken; | ||
if (!accessToken) { | ||
_context13.next = 8; | ||
_context15.next = 8; | ||
break; | ||
} | ||
_context13.next = 8; | ||
_context15.next = 8; | ||
return this.transport.logout(accessToken); | ||
@@ -924,8 +1068,8 @@ | ||
} | ||
_context13.next = 20; | ||
_context15.next = 20; | ||
break; | ||
case 14: | ||
_context13.prev = 14; | ||
_context13.t0 = _context13['catch'](0); | ||
_context15.prev = 14; | ||
_context15.t0 = _context15['catch'](0); | ||
@@ -935,16 +1079,16 @@ this.clearTokens(); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context13.t0); | ||
callback(_context15.t0); | ||
} | ||
throw new _common.AccountsError(_context13.t0.message); | ||
throw new _common.AccountsError(_context15.t0.message); | ||
case 20: | ||
case 'end': | ||
return _context13.stop(); | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee13, this, [[0, 14]]); | ||
}, _callee15, this, [[0, 14]]); | ||
})); | ||
function logout(_x12) { | ||
return _ref15.apply(this, arguments); | ||
function logout(_x13) { | ||
return _ref17.apply(this, arguments); | ||
} | ||
@@ -957,30 +1101,30 @@ | ||
value: function () { | ||
var _ref17 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(token) { | ||
return _regenerator2.default.wrap(function _callee14$(_context14) { | ||
var _ref19 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee16(token) { | ||
return _regenerator2.default.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
_context14.prev = 0; | ||
_context14.next = 3; | ||
_context16.prev = 0; | ||
_context16.next = 3; | ||
return this.transport.verifyEmail(token); | ||
case 3: | ||
_context14.next = 8; | ||
_context16.next = 8; | ||
break; | ||
case 5: | ||
_context14.prev = 5; | ||
_context14.t0 = _context14['catch'](0); | ||
throw new _common.AccountsError(_context14.t0.message); | ||
_context16.prev = 5; | ||
_context16.t0 = _context16['catch'](0); | ||
throw new _common.AccountsError(_context16.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context14.stop(); | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee14, this, [[0, 5]]); | ||
}, _callee16, this, [[0, 5]]); | ||
})); | ||
function verifyEmail(_x13) { | ||
return _ref17.apply(this, arguments); | ||
function verifyEmail(_x14) { | ||
return _ref19.apply(this, arguments); | ||
} | ||
@@ -993,10 +1137,10 @@ | ||
value: function () { | ||
var _ref18 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15(token, newPassword) { | ||
var _ref20 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee17(token, newPassword) { | ||
var hashAlgorithm, password; | ||
return _regenerator2.default.wrap(function _callee15$(_context15) { | ||
return _regenerator2.default.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
if (_common.validators.validatePassword(newPassword)) { | ||
_context15.next = 2; | ||
_context17.next = 2; | ||
break; | ||
@@ -1010,25 +1154,25 @@ } | ||
password = hashAlgorithm ? (0, _encryption.hashPassword)(newPassword, hashAlgorithm) : newPassword; | ||
_context15.prev = 4; | ||
_context15.next = 7; | ||
_context17.prev = 4; | ||
_context17.next = 7; | ||
return this.transport.resetPassword(token, password); | ||
case 7: | ||
_context15.next = 12; | ||
_context17.next = 12; | ||
break; | ||
case 9: | ||
_context15.prev = 9; | ||
_context15.t0 = _context15['catch'](4); | ||
throw new _common.AccountsError(_context15.t0.message); | ||
_context17.prev = 9; | ||
_context17.t0 = _context17['catch'](4); | ||
throw new _common.AccountsError(_context17.t0.message); | ||
case 12: | ||
case 'end': | ||
return _context15.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee15, this, [[4, 9]]); | ||
}, _callee17, this, [[4, 9]]); | ||
})); | ||
function resetPassword(_x14, _x15) { | ||
return _ref18.apply(this, arguments); | ||
function resetPassword(_x15, _x16) { | ||
return _ref20.apply(this, arguments); | ||
} | ||
@@ -1041,9 +1185,9 @@ | ||
value: function () { | ||
var _ref19 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee16(email) { | ||
return _regenerator2.default.wrap(function _callee16$(_context16) { | ||
var _ref21 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee18(email) { | ||
return _regenerator2.default.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context16.next = 2; | ||
_context18.next = 2; | ||
break; | ||
@@ -1055,25 +1199,25 @@ } | ||
case 2: | ||
_context16.prev = 2; | ||
_context16.next = 5; | ||
_context18.prev = 2; | ||
_context18.next = 5; | ||
return this.transport.sendResetPasswordEmail(email); | ||
case 5: | ||
_context16.next = 10; | ||
_context18.next = 10; | ||
break; | ||
case 7: | ||
_context16.prev = 7; | ||
_context16.t0 = _context16['catch'](2); | ||
throw new _common.AccountsError(_context16.t0.message); | ||
_context18.prev = 7; | ||
_context18.t0 = _context18['catch'](2); | ||
throw new _common.AccountsError(_context18.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context16.stop(); | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee16, this, [[2, 7]]); | ||
}, _callee18, this, [[2, 7]]); | ||
})); | ||
function requestPasswordReset(_x16) { | ||
return _ref19.apply(this, arguments); | ||
function requestPasswordReset(_x17) { | ||
return _ref21.apply(this, arguments); | ||
} | ||
@@ -1086,9 +1230,9 @@ | ||
value: function () { | ||
var _ref20 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee17(email) { | ||
return _regenerator2.default.wrap(function _callee17$(_context17) { | ||
var _ref22 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee19(email) { | ||
return _regenerator2.default.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context17.next = 2; | ||
_context19.next = 2; | ||
break; | ||
@@ -1100,25 +1244,25 @@ } | ||
case 2: | ||
_context17.prev = 2; | ||
_context17.next = 5; | ||
_context19.prev = 2; | ||
_context19.next = 5; | ||
return this.transport.sendVerificationEmail(email); | ||
case 5: | ||
_context17.next = 10; | ||
_context19.next = 10; | ||
break; | ||
case 7: | ||
_context17.prev = 7; | ||
_context17.t0 = _context17['catch'](2); | ||
throw new _common.AccountsError(_context17.t0.message); | ||
_context19.prev = 7; | ||
_context19.t0 = _context19['catch'](2); | ||
throw new _common.AccountsError(_context19.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context17.stop(); | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee17, this, [[2, 7]]); | ||
}, _callee19, this, [[2, 7]]); | ||
})); | ||
function requestVerificationEmail(_x17) { | ||
return _ref20.apply(this, arguments); | ||
function requestVerificationEmail(_x18) { | ||
return _ref22.apply(this, arguments); | ||
} | ||
@@ -1138,19 +1282,25 @@ | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee18() { | ||
return _regenerator2.default.wrap(function _callee18$(_context18) { | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee20() { | ||
return _regenerator2.default.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
_this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport); | ||
return _context18.abrupt('return', _this.instance.loadTokensFromStorage().then(function () { | ||
return _this.instance; | ||
})); | ||
_context20.next = 3; | ||
return _this.instance.loadTokensFromStorage(); | ||
case 2: | ||
case 3: | ||
_context20.next = 5; | ||
return _this.instance.loadOriginalTokensFromStorage(); | ||
case 5: | ||
return _context20.abrupt('return', _this.instance); | ||
case 6: | ||
case 'end': | ||
return _context18.stop(); | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee18, _this); | ||
}, _callee20, _this); | ||
}))(); | ||
@@ -1349,3 +1499,4 @@ }, | ||
}, | ||
loginOnSignUp: true | ||
loginOnSignUp: true, | ||
persistImpersonation: true | ||
}); | ||
@@ -1352,0 +1503,0 @@ |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.12-alpha.5e7e66f0", | ||
"version": "0.0.12-alpha.867eb639", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -74,3 +74,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/common": "^0.0.12-alpha.5e7e66f0", | ||
"@accounts/common": "^0.0.12-alpha.867eb639", | ||
"crypto-js": "^3.1.9-1", | ||
@@ -77,0 +77,0 @@ "immutable": "^3.8.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
335020
40
5744