import {Component, OnInit, Inject, ViewContainerRef} from '@angular/core'; import {BehaviorSubject} from 'rxjs'; import { DOCUMENT } from '@angular/common'; import {AuthService} from './services/auth.service'; import {ToastsService} from './services/toasts.service'; import {User, userType} from './models/User'; import {ActivatedRoute, Router} from '@angular/router'; import {ModalService} from './services/modal.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', standalone: false, styleUrl: './app.component.css' }) export class AppComponent implements OnInit { // title = 'ufund-ui'; currentUser?: BehaviorSubject; constructor( private authService: AuthService, private router: Router, private route: ActivatedRoute, protected toastService: ToastsService, private viewContainerRef: ViewContainerRef, protected modalService: ModalService, @Inject(DOCUMENT) private document: Document ) {} reloadPage() { this.document.defaultView?.location.reload(); } ngOnInit() { this.toastService.setRootViewContainerRef(this.viewContainerRef) this.currentUser = this.authService.getCurrentUserSubject() let data = localStorage.getItem("credential"); if (data) { let dataParsed = JSON.parse(data) this.authService.restoreLogin(dataParsed.username, dataParsed.key) console.log("Key found", dataParsed.key) } } login() { this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); } logout() { localStorage.removeItem("credential") location.reload() } protected readonly userType = userType; }