mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Fix access token expires issue (#1554)
This commit is contained in:
parent
1cbe0b7b9f
commit
033e058745
@ -9,8 +9,9 @@ export default function fetchToken(clientId, code) {
|
|||||||
body: data,
|
body: data,
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
if (!resp.ok) throw new Error('Unable to fetch tokens');
|
if (!resp.ok) throw new Error('Unable to fetch tokens');
|
||||||
const tokens = resp.json();
|
return resp.json().then((tokens) => {
|
||||||
tokens.expires = (tokens.expires_in * 1000) + Date.now();
|
tokens.expires = (tokens.expires_in * 1000) + Date.now();
|
||||||
return tokens;
|
return tokens;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,9 @@ export default function refreshAccessToken(clientId, refreshToken) {
|
|||||||
body: data,
|
body: data,
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
if (!resp.ok) throw new Error('Unable to fetch tokens');
|
if (!resp.ok) throw new Error('Unable to fetch tokens');
|
||||||
const tokens = resp.json();
|
return resp.json().then((tokens) => {
|
||||||
tokens.expires = (tokens.expires_in * 1000) + Date.now();
|
tokens.expires = (tokens.expires_in * 1000) + Date.now();
|
||||||
return tokens;
|
return tokens;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ function redirectLogin() {
|
|||||||
|
|
||||||
window.refreshToken = () =>
|
window.refreshToken = () =>
|
||||||
refreshToken_(clientId(), window.tokens.refresh_token).then((accessTokenResp) => {
|
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);
|
localStorage.tokens = JSON.stringify(window.tokens);
|
||||||
return {
|
return {
|
||||||
access_token: accessTokenResp.access_token,
|
access_token: accessTokenResp.access_token,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user