@accounts/client
Advanced tools
Comparing version 0.0.4-alpha.6d363033 to 0.0.4-alpha.fc5e28a4
@@ -95,2 +95,15 @@ 'use strict'; | ||
}, { | ||
key: 'storeTokens', | ||
value: function storeTokens(loginResponse) { | ||
var newAccessToken = loginResponse.tokens.accessToken; | ||
if (newAccessToken) { | ||
localStorage.setItem(getTokenKey(ACCESS_TOKEN, this.options), newAccessToken); | ||
} | ||
var newRefreshToken = loginResponse.tokens.refreshToken; | ||
if (newRefreshToken) { | ||
localStorage.setItem(getTokenKey(REFRESH_TOKEN, this.options), newRefreshToken); | ||
} | ||
} | ||
}, { | ||
key: 'clearUser', | ||
@@ -119,3 +132,3 @@ value: function clearUser() { | ||
if (!(accessToken && refreshToken)) { | ||
_context.next = 25; | ||
_context.next = 24; | ||
break; | ||
@@ -136,3 +149,3 @@ } | ||
this.clearUser(); | ||
_context.next = 16; | ||
_context.next = 15; | ||
break; | ||
@@ -147,12 +160,12 @@ | ||
localStorage.setItem(getTokenKey(ACCESS_TOKEN, this.options), refreshedSession.tokens.accessToken); | ||
localStorage.setItem(getTokenKey(REFRESH_TOKEN, this.options), refreshedSession.tokens.refreshToken); | ||
this.storeTokens(refreshedSession); | ||
this.store.dispatch((0, _module.setUser)(refreshedSession.user)); | ||
case 16: | ||
_context.next = 23; | ||
case 15: | ||
_context.next = 22; | ||
break; | ||
case 18: | ||
_context.prev = 18; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context['catch'](2); | ||
@@ -164,11 +177,11 @@ | ||
case 23: | ||
_context.next = 27; | ||
case 22: | ||
_context.next = 26; | ||
break; | ||
case 25: | ||
case 24: | ||
this.clearTokens(); | ||
this.clearUser(); | ||
case 27: | ||
case 26: | ||
case 'end': | ||
@@ -178,3 +191,3 @@ return _context.stop(); | ||
} | ||
}, _callee, this, [[2, 18]]); | ||
}, _callee, this, [[2, 17]]); | ||
})); | ||
@@ -298,4 +311,3 @@ | ||
localStorage.setItem(getTokenKey(ACCESS_TOKEN, this.options), res.tokens.accessToken); | ||
localStorage.setItem(getTokenKey(REFRESH_TOKEN, this.options), res.tokens.refreshToken); | ||
this.storeTokens(res); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
@@ -306,7 +318,7 @@ this.options.onSignedInHook(); | ||
} | ||
_context3.next = 20; | ||
_context3.next = 19; | ||
break; | ||
case 16: | ||
_context3.prev = 16; | ||
case 15: | ||
_context3.prev = 15; | ||
_context3.t0 = _context3['catch'](5); | ||
@@ -319,6 +331,6 @@ | ||
case 20: | ||
case 19: | ||
this.store.dispatch((0, _module.loggingIn)(false), user); | ||
case 21: | ||
case 20: | ||
case 'end': | ||
@@ -328,3 +340,3 @@ return _context3.stop(); | ||
} | ||
}, _callee3, this, [[5, 16]]); | ||
}, _callee3, this, [[5, 15]]); | ||
})); | ||
@@ -360,6 +372,13 @@ | ||
_tokens2 = this.tokens(), accessToken = _tokens2.accessToken; | ||
_context4.next = 4; | ||
if (!accessToken) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
_context4.next = 5; | ||
return this.transport.logout(accessToken); | ||
case 4: | ||
case 5: | ||
this.clearTokens(); | ||
@@ -371,7 +390,7 @@ this.store.dispatch((0, _module.clearUser)()); | ||
this.options.onSignedOutHook(); | ||
_context4.next = 14; | ||
_context4.next = 15; | ||
break; | ||
case 10: | ||
_context4.prev = 10; | ||
case 11: | ||
_context4.prev = 11; | ||
_context4.t0 = _context4['catch'](0); | ||
@@ -384,3 +403,3 @@ | ||
case 14: | ||
case 15: | ||
case 'end': | ||
@@ -390,3 +409,3 @@ return _context4.stop(); | ||
} | ||
}, _callee4, this, [[0, 10]]); | ||
}, _callee4, this, [[0, 11]]); | ||
})); | ||
@@ -393,0 +412,0 @@ |
@@ -615,2 +615,3 @@ 'use strict'; | ||
}))); | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
@@ -628,14 +629,15 @@ var transport, callback; | ||
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
callback = jest.fn(); | ||
_context18.prev = 3; | ||
_context18.next = 6; | ||
_context18.prev = 4; | ||
_context18.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
case 6: | ||
case 7: | ||
throw new Error(); | ||
case 9: | ||
_context18.prev = 9; | ||
_context18.t0 = _context18['catch'](3); | ||
case 10: | ||
_context18.prev = 10; | ||
_context18.t0 = _context18['catch'](4); | ||
@@ -646,3 +648,3 @@ expect(_context18.t0.message).toEqual('error message'); | ||
case 14: | ||
case 15: | ||
case 'end': | ||
@@ -652,3 +654,3 @@ return _context18.stop(); | ||
} | ||
}, _callee18, undefined, [[3, 9]]); | ||
}, _callee18, undefined, [[4, 10]]); | ||
}))); | ||
@@ -655,0 +657,0 @@ }); |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.4-alpha.6d363033", | ||
"version": "0.0.4-alpha.fc5e28a4", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -14,7 +14,8 @@ "main": "lib/index.js", | ||
"prepublish": "npm run compile", | ||
"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/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"test": "npm run testonly", | ||
"test-ci": "npm lint && npm coverage", | ||
"testonly": "jest", | ||
"flow:check": "flow check", | ||
"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/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"coverage": "npm run testonly -- --coverage", | ||
@@ -67,3 +68,3 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"dependencies": { | ||
"@accounts/common": "^0.0.4-alpha.6d363033", | ||
"@accounts/common": "^0.0.4-alpha.fc5e28a4", | ||
"immutable": "^3.8.1", | ||
@@ -70,0 +71,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
125947
26
2340