diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:47:16 -0400 |
commit | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/app.component.ts | |
parent | bc9d3417795d841b4cb3e9fb022f8d61448af946 (diff) | |
parent | 233fe120d2a9b30e0150401ebdfeb946dc9c2c07 (diff) | |
download | JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.gz JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.tar.bz2 JellySolutions-d8330f1ac85b26d08ca4df5ce3875078d7b4f47f.zip |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
Diffstat (limited to 'ufund-ui/src/app/app.component.ts')
-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() + } } |