import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { Router, RouterLink } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; import { ApiService } from '../../core/api.service'; import { AuthService } from '../../core/auth.service'; import { errorText } from '../../core/models'; import { AuthFrameComponent } from './auth-frame.component'; @Component({ selector: 'app-login', imports: [FormsModule, RouterLink, MatIconModule, AuthFrameComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: `
@if (error()) { }
@if (registration()) {

No mailbox yet? Create one

}
` }) export class LoginPage { private auth = inject(AuthService); private router = inject(Router); email = ''; password = ''; readonly show = signal(false); readonly busy = signal(false); readonly error = signal(''); readonly registration = signal(false); constructor() { inject(ApiService).config().subscribe({ next: c => this.registration.set(c.registrationEnabled), error: () => {} }); } submit(): void { if (!this.email.trim() || !this.password) { this.error.set('Enter the email and the password'); return; } this.busy.set(true); this.error.set(''); this.auth.login(this.email.trim(), this.password).subscribe({ next: () => this.router.navigate(['/']), error: e => { this.busy.set(false); this.error.set(errorText(e) === 'Invalid credentials' ? 'Wrong email or password' : errorText(e)); } }); } }