diff options
Diffstat (limited to '')
-rw-r--r-- | ufund-ui/src/app/app.component.ts | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 86717c4..2f98334 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,7 +1,10 @@ -import {Component, OnInit, Inject} from '@angular/core'; +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} from './models/User'; +import {ActivatedRoute, Router} from '@angular/router'; @Component({ selector: 'app-root', @@ -11,10 +14,14 @@ import {AuthService} from './services/auth.service'; }) export class AppComponent implements OnInit { // title = 'ufund-ui'; - currentUser$: BehaviorSubject<string> = new BehaviorSubject<string>("Logged out."); + currentUser?: BehaviorSubject<User | null>; constructor( private authService: AuthService, + private router: Router, + private route: ActivatedRoute, + protected toastService: ToastsService, + private viewContainerRef: ViewContainerRef, @Inject(DOCUMENT) private document: Document ) {} @@ -23,12 +30,22 @@ export class AppComponent implements OnInit { } ngOnInit() { - this.authService.getCurrentUserSubject().subscribe(r => { - this.currentUser$?.next(r - ? "Logged in as " + r.username - : "Logged out." - ) - }) + 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() + } } |