Fix access token expires issue (#1554)

This commit is contained in:
Jason Hu 2018-08-09 02:17:40 -07:00 committed by Paulus Schoutsen
parent 1cbe0b7b9f
commit 033e058745
3 changed files with 9 additions and 7 deletions

View File

@ -9,8 +9,9 @@ export default function fetchToken(clientId, code) {
body: data,
}).then((resp) => {
if (!resp.ok) throw new Error('Unable to fetch tokens');
const tokens = resp.json();
tokens.expires = (tokens.expires_in * 1000) + Date.now();
return tokens;
return resp.json().then((tokens) => {
tokens.expires = (tokens.expires_in * 1000) + Date.now();
return tokens;
});
});
}

View File

@ -9,8 +9,9 @@ export default function refreshAccessToken(clientId, refreshToken) {
body: data,
}).then((resp) => {
if (!resp.ok) throw new Error('Unable to fetch tokens');
const tokens = resp.json();
tokens.expires = (tokens.expires_in * 1000) + Date.now();
return tokens;
return resp.json().then((tokens) => {
tokens.expires = (tokens.expires_in * 1000) + Date.now();
return tokens;
});
});
}

View File

@ -39,7 +39,7 @@ function redirectLogin() {
window.refreshToken = () =>
refreshToken_(clientId(), window.tokens.refresh_token).then((accessTokenResp) => {
window.tokens.access_token = accessTokenResp.access_token;
window.tokens = Object.assign({}, window.tokens, accessTokenResp);
localStorage.tokens = JSON.stringify(window.tokens);
return {
access_token: accessTokenResp.access_token,