diff --git a/Services/client/src/services/KeyCloakService.ts b/Services/client/src/services/KeyCloakService.ts index 8c7ce11..dfa2662 100644 --- a/Services/client/src/services/KeyCloakService.ts +++ b/Services/client/src/services/KeyCloakService.ts @@ -2,15 +2,20 @@ import Keycloak from 'keycloak-js' const keycloak = new Keycloak('/keycloak.json') -export async function login(cb?: (...args: any[]) => void) { - const auth = await keycloak - .init({ - onLoad: 'login-required', - responseMode: 'query', - checkLoginIframe: false, - }) - .catch((e) => console.dir(e)) +let init = false +export async function login(cb?: (...args: any[]) => void) { + const auth = !init + ? await keycloak + .init({ + onLoad: 'login-required', + responseMode: 'query', + checkLoginIframe: false, + }) + .catch((e) => console.dir(e)) + : await keycloak.login().catch((e) => console.dir(e)) + + if (auth) init = true if (auth && cb) cb() }