From 22c0c250e0f4adb2891a3e1b0e8cb6d647dac4d9 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 13 May 2024 13:39:38 +0200 Subject: [PATCH] V14: The login page does not respect certain error codes (#16244) * handle 403 and unknown error codes from the server * resolve 2fa errors in repository error handling was never being activated because this specific endpoint did not return api errors as it works exactly like the "authorize" endpoint, which is being called directly * chore: add obsolete message to unused `SetupViewPath` * chore: remove unused events * add missing labels * fix: send only 'error' back if the response is not ok * chore: remove duplicate error handling for 500 errors * fix: add hack to allow to submit the form on enter click --- .../Security/TwoFactorLoginViewOptions.cs | 1 + .../components/pages/login.page.element.ts | 9 ++- .../src/components/pages/mfa.page.element.ts | 48 +++++-------- .../src/contexts/auth.repository.ts | 68 +++++++++++-------- .../src/localization/lang/da-dk.ts | 2 + .../src/localization/lang/de-de.ts | 2 + .../src/localization/lang/en-us.ts | 2 + .../src/localization/lang/en.ts | 2 + .../src/localization/lang/nb-no.ts | 2 + .../src/localization/lang/nl-nl.ts | 2 + .../src/localization/lang/sv-se.ts | 2 + 11 files changed, 77 insertions(+), 63 deletions(-) diff --git a/src/Umbraco.Cms.Api.Management/Security/TwoFactorLoginViewOptions.cs b/src/Umbraco.Cms.Api.Management/Security/TwoFactorLoginViewOptions.cs index 44cc9db3a7..d045797f10 100644 --- a/src/Umbraco.Cms.Api.Management/Security/TwoFactorLoginViewOptions.cs +++ b/src/Umbraco.Cms.Api.Management/Security/TwoFactorLoginViewOptions.cs @@ -8,5 +8,6 @@ public class TwoFactorLoginViewOptions /// /// Gets or sets the path of the view to show when setting up this 2fa provider /// + [Obsolete("Register the view in the backoffice instead. This will be removed in version 15.")] public string? SetupViewPath { get; set; } } diff --git a/src/Umbraco.Web.UI.Login/src/components/pages/login.page.element.ts b/src/Umbraco.Web.UI.Login/src/components/pages/login.page.element.ts index 234dbad9fd..55d10ebf8f 100644 --- a/src/Umbraco.Web.UI.Login/src/components/pages/login.page.element.ts +++ b/src/Umbraco.Web.UI.Login/src/components/pages/login.page.element.ts @@ -42,6 +42,12 @@ export default class UmbLoginPageElement extends UmbLitElement { if (!this.#formElement) return; + // We need to listen for the enter key to submit the form, because the uui-button does not support the native input fields submit event + this.#formElement.addEventListener('keypress', (e) => { + if (e.key === 'Enter') { + this.#onSubmitClick(); + } + }); this.#formElement.onsubmit = this.#handleSubmit; } @@ -91,7 +97,6 @@ export default class UmbLoginPageElement extends UmbLitElement { } if (response.error) { - this.dispatchEvent(new CustomEvent('umb-login-failed', {bubbles: true, composed: true})); return; } @@ -100,8 +105,6 @@ export default class UmbLoginPageElement extends UmbLitElement { if (returnPath) { location.href = returnPath; } - - this.dispatchEvent(new CustomEvent('umb-login-success', {bubbles: true, composed: true, detail: response.data})); }; get #greetingLocalizationKey() { diff --git a/src/Umbraco.Web.UI.Login/src/components/pages/mfa.page.element.ts b/src/Umbraco.Web.UI.Login/src/components/pages/mfa.page.element.ts index e047f7868f..5d54567fbb 100644 --- a/src/Umbraco.Web.UI.Login/src/components/pages/mfa.page.element.ts +++ b/src/Umbraco.Web.UI.Login/src/components/pages/mfa.page.element.ts @@ -56,6 +56,7 @@ export default class UmbMfaPageElement extends UmbLitElement { if (codeInput) { codeInput.error = false; codeInput.errorMessage = ''; + codeInput.setCustomValidity(''); } if (!form.checkValidity()) return; @@ -84,44 +85,30 @@ export default class UmbMfaPageElement extends UmbLitElement { this.buttonState = 'waiting'; - try { - const response = await this.#authContext.validateMfaCode(code, provider); - if (response.error) { - if (codeInput) { - codeInput.error = true; - codeInput.errorMessage = response.error; - } else { - this.error = response.error; - } - this.buttonState = 'failed'; - return; - } - - this.buttonState = 'success'; - - const returnPath = this.#authContext.returnPath; - if (returnPath) { - location.href = returnPath; - } - - this.dispatchEvent( - new CustomEvent('umb-login-success', {bubbles: true, composed: true}) - ); - } catch (e) { - if (e instanceof Error) { - this.error = e.message ?? 'Unknown error'; + const response = await this.#authContext.validateMfaCode(code, provider); + if (response.error) { + if (codeInput) { + codeInput.error = true; + codeInput.errorMessage = response.error; } else { - this.error = 'Unknown error'; + this.error = response.error; } this.buttonState = 'failed'; - this.dispatchEvent(new CustomEvent('umb-login-failed', {bubbles: true, composed: true})); + return; + } + + this.buttonState = 'success'; + + const returnPath = this.#authContext.returnPath; + if (returnPath) { + location.href = returnPath; } } protected renderDefaultView() { return html` -
+