Newer
Older
import {Component} from '@angular/core';
import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
import {LogInDialogComponent} from './components/log-in-dialog/log-in-dialog.component';
import {AuthServiceService} from './services/auth-service.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
isAuthenticated: boolean = false;
constructor(
private dialog: MatDialog,
private authService: AuthServiceService
ngOnInit(): void {
this.refreshAuth();
}
refreshAuth(): void {
this.authService.isAuthenticated()
.subscribe(isAuthenticated => this.isAuthenticated = isAuthenticated);
}
handleLogInClick() {
const dialogConfig = new MatDialogConfig();
const dialogRef = this.dialog.open(LogInDialogComponent, dialogConfig);
dialogRef.afterClosed().subscribe(data => this.onLogInClose(data));
}
onLogInClose(data: boolean | null): void {
if (data != null || data) {
this.refreshAuth();
}
}
handleLogOutClick() {
this.authService.logOut()
if (success) {
this.refreshAuth();
}
});
}