mvp-ticket/frontend/src/app/app.component.ts

34 lines
884 B
TypeScript
Raw Normal View History

2024-05-30 14:34:18 +02:00
import { Component, OnInit } from '@angular/core';
import { RouterOutlet, Router } from '@angular/router';
2024-05-21 21:21:33 +02:00
import { AuthService } from './shared/service';
2024-03-14 19:58:24 +01:00
@Component({
selector: 'app-root',
standalone: true,
2024-05-30 14:34:18 +02:00
providers: [],
2024-03-14 19:58:24 +01:00
imports: [RouterOutlet],
templateUrl: './app.component.html',
2024-03-14 20:32:51 +01:00
styleUrl: './app.component.scss',
2024-03-14 19:58:24 +01:00
})
2024-05-30 14:34:18 +02:00
export class AppComponent implements OnInit {
public constructor(
private readonly authService: AuthService,
private readonly router: Router
) {}
public ngOnInit(): void {
this.checkAuthentication();
}
private checkAuthentication(): void {
this.authService.isAuthenticated$.subscribe((isAuthenticated: boolean) => {
if (isAuthenticated) {
console.log('User is authenticated');
this.router.navigateByUrl('dashboard');
} else {
this.router.navigateByUrl('signup');
}
});
}
2024-05-21 21:21:33 +02:00
}