From 7100ed44e08729a6d7b4f35f5e1321c78cf91225 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 2 Jun 2020 09:40:50 +0200
Subject: [PATCH] Handle logout being aborted in beforeunload

If the page prevents the default handler in beforeunload the logout
never occurs and we end up in an endless transient "logging-out" state.

Prevent this by reverting the login status back in that case.
---
 packages/auth/src/auth.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/packages/auth/src/auth.js b/packages/auth/src/auth.js
index 27c128a2..683c61c9 100644
--- a/packages/auth/src/auth.js
+++ b/packages/auth/src/auth.js
@@ -270,6 +270,11 @@ export class Auth extends ScopedElementsMixin(VPULitElement) {
             this._setLoginStatus(LoginStatus.LOGGING_OUT);
         }
         this._kcwrapper.logout();
+        // In case logout was aborted, for example with beforeunload,
+        // revert back to being logged in
+        if (this._loginStatus === LoginStatus.LOGGING_OUT) {
+            this._setLoginStatus(LoginStatus.LOGGED_IN);
+        }
     }
 
     update(changedProperties) {
-- 
GitLab