oauth disabling API

This commit is contained in:
Jan Prochazka
2022-11-17 20:09:27 +01:00
parent 94a91d5fed
commit 07b2a3e923
4 changed files with 31 additions and 26 deletions

View File

@@ -4,16 +4,17 @@ import { writable } from 'svelte/store';
import getElectron from './getElectron';
// import socket from './socket';
import { showSnackbarError } from '../utility/snackbar';
import { redirectToLogin } from '../clientAuth';
import { isOauthCallback, redirectToLogin } from '../clientAuth';
let eventSource;
let apiLogging = false;
// let cacheCleanerRegistered;
let apiDisabled = false;
const disabledOnOauth = isOauthCallback();
// export function disableApi() {
// apiDisabled = true;
// }
export function disableApi() {
apiDisabled = true;
}
function wantEventSource() {
if (!eventSource) {
@@ -45,6 +46,10 @@ export async function apiCall(route: string, args: {} = undefined) {
console.log('API disabled!!', route);
return;
}
if (disabledOnOauth && route != 'auth/oauth-token') {
console.log('API disabled because oauth callback!!', route);
return;
}
const electron = getElectron();
if (electron) {
@@ -62,7 +67,7 @@ export async function apiCall(route: string, args: {} = undefined) {
});
if (resp.status == 401 && !apiDisabled) {
apiDisabled = true;
disableApi();
console.log('Disabling API', route);
// unauthorized
redirectToLogin();