add error text
This commit is contained in:
@@ -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) };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user