Skip to content

Commit b36b8b0

Browse files
committed
Added danger alert when wrong credentials are provided
1 parent c36399e commit b36b8b0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/app/modules/auth/pages/login/login.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Password: 12345
44
</div>
55

6+
<div [hidden]="!error" class="alert alert-danger">
7+
{{ error }}
8+
</div>
9+
610
<form (ngSubmit)="login()" [formGroup]="loginForm">
711
<div class="form-group">
812
<label class="d-block">
@@ -14,7 +18,7 @@
1418
<app-control-messages [control]="f['password']"></app-control-messages>
1519
</label>
1620
<div class="form-group">
17-
<button type="submit" class="btn btn-primary btn-block btn-raised" type="submit">
21+
<button type="submit" class="btn btn-primary btn-block btn-raised" type="submit" [disabled]="loginForm.invalid">
1822
<span [hidden]="isLoading">Submit</span>
1923
<span [hidden]="!isLoading"><i class="fas fa-asterisk fa-2x fa-spin"></i></span>
2024
</button>

src/app/modules/auth/pages/login/login.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
4-
import { tap, delay, finalize } from 'rxjs/operators';
4+
import { tap, delay, finalize, catchError } from 'rxjs/operators';
5+
import { of } from 'rxjs';
56

67
import { AuthService } from '@app/core';
78

@@ -39,9 +40,8 @@ export class LoginComponent implements OnInit {
3940
.pipe(
4041
delay(5000),
4142
tap(user => this.router.navigate(['/dashboard/home'])),
42-
finalize(() => {
43-
this.isLoading = false;
44-
})
43+
finalize(() => this.isLoading = false),
44+
catchError(error => of(this.error = error))
4545
).subscribe();
4646
}
4747

0 commit comments

Comments
 (0)