import { Component } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; import { AuthService } from '../../cores/services/auth.service'; import { StorageService } from '../../cores/services/storage.service'; import { FormsModule } from '@angular/forms'; import { LoginData } from '../../cores/interface/auth'; import { ToastrService } from 'ngx-toastr'; @Component({ selector: 'app-auth', standalone: true, imports: [FormsModule, RouterModule], templateUrl: './auth.component.html', styleUrls: ['./auth.component.scss'] }) export class AuthComponent { email: string = ''; password: string = ''; rememberMe: boolean = false; constructor(private authService: AuthService, private storageService: StorageService, private router: Router, private toastr: ToastrService) {} onSubmit() { const loginData: LoginData = { email: this.email, password: this.password, rememberMe: this.rememberMe }; this.authService.login(loginData).subscribe( (response) => { this.storageService.saveToken(response.data.token); this.router.navigate(['/dashboard']); this.toastr.success('Login successful'); }, (error) => { this.toastr.error(error.error.message); } ); } }