import { Component, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { AuthService } from '../../services/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-login',
standalone: true,
imports: [RouterLink, FormsModule],
template: `
M
Sign in to your mailbox
@if (error) {
{{ error }}
}
No account?
Register here
`,
styles: ``
})
export default class LoginComponent {
private authService = inject(AuthService);
private router = inject(Router);
email = '';
password = '';
error = '' as string | null;
loading = false as boolean;
onLogin(): void {
this.loading = true;
this.error = null;
this.authService.login({ email: this.email, password: this.password }).subscribe({
next: () => this.router.navigate(['/inbox']),
error: (err) => {
this.error = 'Invalid email or password';
this.loading = false;
}
});
}
}