From ab154dc4de8148beb3ca4f3388a67748de7b0235 Mon Sep 17 00:00:00 2001 From: zogstrip Date: Thu, 7 Aug 2025 13:32:24 +0200 Subject: [PATCH] FIX: show loading spinner when redirecting to discourse connect On "slow" computers and/or in production builds of the client-side application, the redirection to discourse connect (via window.location) might happen _after_ the login/signup route is done loading and the login/signup template is being shown. Since when discourse connect is enabled, no other auth "provider" is allowed, we "flashed" a screen that indicated there was no "login method" configured. In order to fix this, we rely on the "isRedirectingToExternalAuth" boolean and ensure it's set to "true" when discourse connect is enabled. This is unfortunately ~~impossible~~ very hard to test as it depends on how fast the browser running the test is... --- app/assets/javascripts/discourse/app/routes/login.js | 10 +++++++--- app/assets/javascripts/discourse/app/routes/signup.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/routes/login.js b/app/assets/javascripts/discourse/app/routes/login.js index de7292473faf4..3042dbdcab62d 100644 --- a/app/assets/javascripts/discourse/app/routes/login.js +++ b/app/assets/javascripts/discourse/app/routes/login.js @@ -17,7 +17,7 @@ export default class extends DiscourseRoute { @service site; @service siteSettings; - isRedirecting = false; + #isRedirecting = false; beforeModel(transition) { const { from, wantsTo } = transition; @@ -69,7 +69,7 @@ export default class extends DiscourseRoute { // Automatically kick off the external login if it's the only one available if (isOnlyOneExternalLoginMethod) { if (auth_immediately || login_required || !from || wantsTo) { - this.isRedirecting = true; + this.#isRedirecting = true; singleExternalLogin(); } else { router.replaceWith("discovery.login-required"); @@ -78,6 +78,8 @@ export default class extends DiscourseRoute { } setupController(controller) { + const { enable_discourse_connect } = this.siteSettings; + super.setupController(...arguments); // We're in the middle of an authentication flow @@ -85,6 +87,8 @@ export default class extends DiscourseRoute { return; } - controller.isRedirectingToExternalAuth = this.isRedirecting; + // Shows the loading spinner while waiting for the redirection to external auth + controller.isRedirectingToExternalAuth = + this.#isRedirecting || enable_discourse_connect; } } diff --git a/app/assets/javascripts/discourse/app/routes/signup.js b/app/assets/javascripts/discourse/app/routes/signup.js index 1b05884070ac1..fc75a24e6bd6e 100644 --- a/app/assets/javascripts/discourse/app/routes/signup.js +++ b/app/assets/javascripts/discourse/app/routes/signup.js @@ -18,7 +18,7 @@ export default class extends DiscourseRoute { @service site; @service siteSettings; - isRedirecting = false; + #isRedirecting = false; beforeModel(transition) { const { from, wantsTo } = transition; @@ -82,7 +82,7 @@ export default class extends DiscourseRoute { // Automatically kick off the external login if it's the only one available if (isOnlyOneExternalLoginMethod) { if (auth_immediately || login_required || !from || wantsTo) { - this.isRedirecting = true; + this.#isRedirecting = true; singleExternalLogin({ signup: true }); } else { router.replaceWith("discovery.login-required"); @@ -91,6 +91,8 @@ export default class extends DiscourseRoute { } setupController(controller) { + const { enable_discourse_connect } = this.siteSettings; + super.setupController(...arguments); // We're in the middle of an authentication flow @@ -98,6 +100,8 @@ export default class extends DiscourseRoute { return; } - controller.isRedirectingToExternalAuth = this.isRedirecting; + // Shows the loading spinner while waiting for the redirection to external auth + controller.isRedirectingToExternalAuth = + this.#isRedirecting || enable_discourse_connect; } }