import { Component, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthService } from '../../core/services/auth.service'; @Component({ selector: 'app-login', standalone: true, imports: [CommonModule, FormsModule], template: `

Onebox

Sign in to your account

@if (error) {

{{ error }}

}

Default credentials: admin / admin

Please change after first login

`, }) export class LoginComponent { private authService = inject(AuthService); private router = inject(Router); username = ''; password = ''; loading = false; error = ''; onSubmit(): void { this.error = ''; this.loading = true; this.authService.login({ username: this.username, password: this.password }).subscribe({ next: (response) => { this.loading = false; if (response.success) { this.router.navigate(['/dashboard']); } else { this.error = response.error || 'Login failed'; } }, error: (err) => { this.loading = false; this.error = err.error?.error || 'An error occurred during login'; }, }); } }