From cd6d0a47f3894fa083312ffef151e1d62a2232a1 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 23:36:59 +0100 Subject: [PATCH] web/user: fix race condition in user settings flow executor (cherry-pick #13163) (#13169) web/user: fix race condition in user settings flow executor (#13163) Signed-off-by: Jens Langhammer Co-authored-by: Jens L. --- web/src/elements/Interface/brandProvider.ts | 2 ++ .../details/UserSettingsFlowExecutor.ts | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/web/src/elements/Interface/brandProvider.ts b/web/src/elements/Interface/brandProvider.ts index 912466d963..170225e462 100644 --- a/web/src/elements/Interface/brandProvider.ts +++ b/web/src/elements/Interface/brandProvider.ts @@ -3,6 +3,7 @@ import type { AbstractConstructor } from "@goauthentik/elements/types.js"; import { consume } from "@lit/context"; import type { LitElement } from "lit"; +import { state } from "lit/decorators.js"; import type { CurrentBrand } from "@goauthentik/api"; @@ -12,6 +13,7 @@ export function WithBrandConfig>( ) { abstract class WithBrandProvider extends superclass { @consume({ context: authentikBrandContext, subscribe }) + @state() public brand!: CurrentBrand; } return WithBrandProvider; diff --git a/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts b/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts index 4ad334e59e..1384469cf7 100644 --- a/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts +++ b/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts @@ -10,7 +10,7 @@ import { StageHost } from "@goauthentik/flow/stages/base"; import "@goauthentik/user/user-settings/details/stages/prompt/PromptStage"; import { msg } from "@lit/localize"; -import { CSSResult, TemplateResult, html } from "lit"; +import { CSSResult, PropertyValues, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; @@ -83,12 +83,14 @@ export class UserSettingsFlowExecutor }); } - firstUpdated(): void { - this.flowSlug = this.brand?.flowUserSettings; - if (!this.flowSlug) { - return; + updated(changedProperties: PropertyValues): void { + if (changedProperties.has("brand") && this.brand) { + this.flowSlug = this.brand?.flowUserSettings; + if (!this.flowSlug) { + return; + } + this.nextChallenge(); } - this.nextChallenge(); } async nextChallenge(): Promise { @@ -161,7 +163,7 @@ export class UserSettingsFlowExecutor // Flow has finished, so let's load while in the background we can restart the flow this.loading = true; console.debug("authentik/user/flows: redirect to '/', restarting flow."); - this.firstUpdated(); + this.nextChallenge(); this.globalRefresh(); showMessage({ level: MessageLevel.success,