diff --git a/src/Umbraco.Web.UI.Client/apps/auth/src/auth.context.ts b/src/Umbraco.Web.UI.Client/apps/auth/src/auth.context.ts index b2c224191f..274368a825 100644 --- a/src/Umbraco.Web.UI.Client/apps/auth/src/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/apps/auth/src/auth.context.ts @@ -3,6 +3,16 @@ import { LoginRequestModel, IUmbAuthContext } from './types'; export class UmbAuthContext implements IUmbAuthContext { readonly #AUTH_URL = '/umbraco/management/api/v1/security/back-office'; + getErrorText(response: Response) { + switch (response.status) { + case 401: + return 'Oops! It seems like your login credentials are invalid or expired. Please double-check your username and password and try again.'; + + default: + return response.statusText; + } + } + async login(data: LoginRequestModel) { //TODO: call authUrl with data const request = new Request(this.#AUTH_URL + '/login', { @@ -17,20 +27,6 @@ export class UmbAuthContext implements IUmbAuthContext { }); const response = await fetch(request); - return { error: response.ok ? undefined : response.statusText }; - } -} - -class UmbMockAPI { - static async loginSuccess(data: LoginRequestModel) { - await new Promise((resolve) => setTimeout(resolve, 1000)); - - return {}; - } - - static async loginFail(data: LoginRequestModel) { - await new Promise((resolve) => setTimeout(resolve, 1000)); - - return { error: 'Invalid credentials' }; + return { error: response.ok ? undefined : this.getErrorText(response) }; } }