Compare commits

...
+16 -1
View File
@@ -75,11 +75,26 @@ const clearUrlParams = () => {
}
};
// The login page is never cached, so check the server is up before getAuth redirects to it.
const loadTokensOrCheckServer = async () => {
const tokens = loadTokens();
if (!tokens || tokens.hassUrl !== hassUrl) {
const response = await fetch(`${hassUrl}/manifest.json`, {
mode: "no-cors",
cache: "no-store",
});
if (response.status >= 500) {
throw new Error(`Home Assistant responded with ${response.status}`);
}
}
return tokens;
};
const authOptions = {
hassUrl,
limitHassInstance: true,
saveTokens,
loadTokens: () => Promise.resolve(loadTokens()),
loadTokens: loadTokensOrCheckServer,
};
const getAuthDroppingStaleCallback = async () => {