Files
itzmineydev/src/app/login/login.component.ts
T
itzMiney e7ed9f047f
Frontend CI/CD / test-and-build (push) Successful in 25s
Frontend CI/CD / deploy (push) Successful in 26s
refactored seo helper, adjusted meta tags & added a shitload more buttons to discord component embeds
2026-11-08 21:27:37 +01:00

61 lines
1.6 KiB
TypeScript

import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {AuthService} from '../shared/services/auth.service';
import {Router} from '@angular/router';
import {FormsModule} from '@angular/forms';
import {ViewportService} from '../shared/services/viewport.service';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
changeDetection: ChangeDetectionStrategy.Eager,
imports: [
FormsModule,
ParallaxComponent
]
})
export class LoginComponent implements OnInit {
username = '';
password = '';
errorMessage = '';
isNarrow = false;
constructor(
private authService: AuthService,
private router: Router,
private deviceService: ViewportService,
private seo: SeoService,
) {}
ngOnInit() {
this.seo.update({
title: 'Admin Panel',
desc: 'Management & Administration Panel',
buttons: [{ label: 'Log-in', url: this.seo.getpath() }]
})
this.isNarrow = this.deviceService.isNarrow;
if (this.authService.token) {
void this.router.navigate(['/admin']);
}
}
onLogin() {
this.errorMessage = '';
this.authService.login(this.username.trim(), this.password).subscribe({
next: () => {
void this.router.navigate(['/admin']);
},
error: (err) => {
this.errorMessage =
err?.error?.message ?? 'An error occurred. Please try again later.';
console.error('Login error:', err);
}
});
}
}