better oauth handle

This commit is contained in:
Jan Prochazka
2022-11-17 19:55:01 +01:00
parent 576fc2062c
commit 94a91d5fed
5 changed files with 58 additions and 30 deletions

View File

@@ -9,7 +9,7 @@ import { redirectToLogin } from '../clientAuth';
let eventSource;
let apiLogging = false;
// let cacheCleanerRegistered;
// let apiDisabled = false;
let apiDisabled = false;
// export function disableApi() {
// apiDisabled = true;
@@ -41,6 +41,10 @@ export async function apiCall(route: string, args: {} = undefined) {
if (apiLogging) {
console.log('>>> API CALL', route, args);
}
if (apiDisabled) {
console.log('API disabled!!', route);
return;
}
const electron = getElectron();
if (electron) {
@@ -57,7 +61,9 @@ export async function apiCall(route: string, args: {} = undefined) {
body: JSON.stringify(args),
});
if (resp.status == 401) {
if (resp.status == 401 && !apiDisabled) {
apiDisabled = true;
console.log('Disabling API', route);
// unauthorized
redirectToLogin();
}