Skip to content

Commit d359156

Browse files
committed
Simplified login failure handling
1 parent bc84a2b commit d359156

5 files changed

Lines changed: 6 additions & 10 deletions

File tree

src/app/authentication/service/authentication.service.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class AuthenticationService {
2424
const toUser = (status: LoginStatus) => this.loadUser(username, password, status);
2525

2626
return this.http.post<ApiResponse<LoginStatus>>(this.loginUrl, { username, password })
27-
.pipe(catchError(this.handleError))
2827
.pipe(map(response => response.content))
2928
.pipe(map(toUser));
3029
}
@@ -53,8 +52,4 @@ export class AuthenticationService {
5352
return this.user;
5453
}
5554

56-
private handleError(error: HttpErrorResponse) {
57-
return throwError(() => new Error(error.message));
58-
}
59-
6055
}

src/app/login/components/login-form/login-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h4 class="card-header">Login</h4>
2323
<span *ngIf="loading" class="spinner-border spinner-border-sm mr-1"></span>
2424
Login
2525
</button>
26-
<div *ngIf="error" class="alert alert-danger mt-3 mb-0">{{error}}</div>
26+
<div *ngIf="failed" class="alert alert-danger mt-3 mb-0">Invalid user</div>
2727
</form>
2828
</div>
2929
</div>

src/app/login/components/login-form/login-form.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class LoginFormComponent {
1111

1212
@Input() public loading = false;
1313

14-
@Input() public error = '';
14+
@Input() public failed = false;
1515

1616
@Output() public login = new EventEmitter<LoginUser>();
1717

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<login-form (login)="onLogin($event)" [error]="error" [loading]="loading"></login-form>
1+
<login-form (login)="onLogin($event)" [failed]="failed" [loading]="loading"></login-form>

src/app/login/view/login-view/login-view.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class LoginViewComponent implements OnInit {
1313

1414
public loading = false;
1515

16-
public error = '';
16+
public failed = false;
1717

1818
private returnUrl: string = '';
1919

@@ -37,13 +37,14 @@ export class LoginViewComponent implements OnInit {
3737
this.authenticationService.login(login.username, login.password)
3838
.subscribe({
3939
next: user => {
40+
this.failed = false;
4041
this.loading = false;
4142
if (user.logged) {
4243
this.router.navigate([this.returnUrl]);
4344
}
4445
},
4546
error: error => {
46-
this.error = error;
47+
this.failed = true;
4748
this.loading = false;
4849
}
4950
});

0 commit comments

Comments
 (0)