Skip to content

Commit

Permalink
Added login & register error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
turkovicf committed Aug 18, 2024
1 parent c04e944 commit 4894fa8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
</button>
</div>

<div class="text-center">
<p>
{{ errorMessage }}
</p>
</div>

<div class="text-center">
<p>
Not a member?
Expand Down
3 changes: 1 addition & 2 deletions src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class LoginComponent {
this.router.navigate(['/home']);
},
(error: any) => {
this.errorMessage = 'Error loging in'; // Postavi errorMessage
//console.error('Greška prilikom prijavljivanja:', error);
this.errorMessage = error.error;
}
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
placeholder="Enter your username"
/>
</div>
<div data-mdb-input-init class="form-outline mb-4">
<div data-mdb-input-init class="form-outline mb-2">
<label class="form-label" for="form2Example2">Password</label>
<input
type="password"
Expand All @@ -48,6 +48,12 @@
</button>
</div>

<div class="text-center">
<p>
{{ errorMessage }}
</p>
</div>

<div class="text-center">
<p>
Already have an account?
Expand Down
8 changes: 6 additions & 2 deletions src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ export class RegisterComponent {
username: string = '';
password: string = '';
email: string = '';
errorMessage: string = '';

constructor(private authService: AuthService, private router: Router) {}

register(): void {
this.authService
.register(this.username, this.email, this.password)
.subscribe(() => {
.subscribe((response) => {
this.username = '';
this.email = '';
this.password = '';
alert('Registration successful!');
this.router.navigate(['/login']);
});
},
(error) => {
this.errorMessage = "Error registering user.";
});
}
}

0 comments on commit 4894fa8

Please sign in to comment.