From a546792e399053a758ecf85bda73533979e0b9e6 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Pasquier <contact@jbpasquier.eu>
Date: Mon, 5 Jul 2021 23:18:29 +0200
Subject: [PATCH] feature: do not login if in the login process

---
 src/scripts/login-element-visibility.js | 6 ++++--
 src/scripts/navigate-event.js           | 6 ++++--
 src/scripts/orbit-auto-login.js         | 3 ++-
 src/scripts/user-creation-form.js       | 3 ++-
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/scripts/login-element-visibility.js b/src/scripts/login-element-visibility.js
index d304f3e3..f7e6eb2a 100644
--- a/src/scripts/login-element-visibility.js
+++ b/src/scripts/login-element-visibility.js
@@ -2,7 +2,8 @@ window.requestLogin = false;
 document.addEventListener("DOMContentLoaded", function () {
   const sibAuth = document.querySelector("sib-auth");
   const timeoutNoUser = setTimeout(() => {
-    sibAuth.login();
+    if(!(new URLSearchParams(window.location.search)).get('code'))
+      sibAuth.login();
   }, 15000);
   if (sibAuth) {
     sibAuth.getUser()
@@ -58,6 +59,7 @@ if (loginButton) {
     setTimeout(() => {
       document.querySelector('#something-goes-wrong').removeAttribute('hidden');
     }, 5000);
-    document.querySelector('sib-auth').login();
+    if(!(new URLSearchParams(window.location.search)).get('code'))
+      document.querySelector('sib-auth').login();
   });
 }
\ No newline at end of file
diff --git a/src/scripts/navigate-event.js b/src/scripts/navigate-event.js
index 86d311a8..238d9612 100644
--- a/src/scripts/navigate-event.js
+++ b/src/scripts/navigate-event.js
@@ -82,7 +82,8 @@ document.addEventListener("DOMContentLoaded", function () {
   if (window.location.pathname == "/login") {
     const sibAuth = document.querySelector("sib-auth");
     const timeoutNoUser = setTimeout(() => {
-      sibAuth.login();
+      if(!(new URLSearchParams(window.location.search)).get('code'))
+        sibAuth.login();
     }, 15000);
     if (sibAuth) {
       sibAuth.getUser()
@@ -129,7 +130,8 @@ document.addEventListener("DOMContentLoaded", function () {
     if (e.detail.route.startsWith('login')) {
       const sibAuth = document.querySelector("sib-auth");
       const timeoutNoUser2 = setTimeout(() => {
-        sibAuth.login();
+        if((new URLSearchParams(window.location.search)).get('code'))
+          sibAuth.login();
       }, 15000);
       if (sibAuth) {
         sibAuth.getUser()
diff --git a/src/scripts/orbit-auto-login.js b/src/scripts/orbit-auto-login.js
index 938a6091..905f60be 100644
--- a/src/scripts/orbit-auto-login.js
+++ b/src/scripts/orbit-auto-login.js
@@ -14,7 +14,8 @@ import(`https://cdn.skypack.dev/@startinblox/core@${core.version}`).then(core =>
             }
           }),
         );
-        document.querySelector("sib-auth").login();
+        if(!(new URLSearchParams(window.location.search)).get('code'))
+          document.querySelector("sib-auth").login();
       }
     }
   });
diff --git a/src/scripts/user-creation-form.js b/src/scripts/user-creation-form.js
index 32229add..28cd58e5 100644
--- a/src/scripts/user-creation-form.js
+++ b/src/scripts/user-creation-form.js
@@ -3,7 +3,8 @@ document.addEventListener('DOMContentLoaded', () => {
   if (userCreationForm) {
     userCreationForm.addEventListener('save', event => {
       if (event.originalTarget.id == 'user-creation-form') {
-        document.querySelector("sib-auth").login();
+        if(!(new URLSearchParams(window.location.search)).get('code'))
+          document.querySelector("sib-auth").login();
       }
     });
   }
-- 
GitLab