From c87095e34274ac9c19813b5ff16f4b1acfbed7ee Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Mon, 20 Jan 2020 16:07:50 +0100
Subject: [PATCH] Retry the keycloak init in case it fails.

See https://gitlab.tugraz.at/VPU/Apps/Library/issues/41

Not sure if this helps, but worth a try.
---
 packages/auth/src/keycloak.js | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/packages/auth/src/keycloak.js b/packages/auth/src/keycloak.js
index 206856e9..cb55e563 100644
--- a/packages/auth/src/keycloak.js
+++ b/packages/auth/src/keycloak.js
@@ -88,6 +88,16 @@ export class KeycloakWrapper extends EventTarget {
         this._keycloak.onReady = this._onReady.bind(this);
     }
 
+    async _keycloakInit(options) {
+        // https://gitlab.tugraz.at/VPU/Apps/Library/issues/41
+        // retry the keycloak init in case it fails, maybe it helps :/
+        try {
+            return await this._keycloak.init(options);
+        } catch (e) {
+            return await this._keycloak.init(options);
+        }
+    }
+
     async _ensureInit() {
         await this._ensureInstance();
         if (this._initDone)
@@ -105,12 +115,12 @@ export class KeycloakWrapper extends EventTarget {
 
             // When silent-sso-check is active but the iframe doesn't load/work we will
             // never return here, so add a timeout and emit a signal so the app can continue
-            await promiseTimeout(5000, this._keycloak.init(options)).catch(() => {
+            await promiseTimeout(5000, this._keycloakInit(options)).catch(() => {
                 console.log('Login timed out');
                 this._onChanged();
             });
         } else {
-            await this._keycloak.init(options);
+            await this._keycloakInit(options);
         }
     }
 
-- 
GitLab