From 8d6129590a5db04bfe9f2b9827bb0ce18ed240a1 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Mon, 26 Sep 2022 17:59:36 +0200 Subject: [PATCH] Fixing user info reading at page load --- src/app/pages/home/home.component.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index b73d386..39c9e1a 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -17,8 +17,20 @@ export class HomeComponent implements OnInit { } ngOnInit(): void { - // TODO: First try to read existing session data - this.authenticateUser(); + if(!HomeComponent.sessionDataAvailable()) { + this.authenticateUser(); + window.location.reload(); + } + } + + /** + * Checks if there is session data saved in the local storage + * @return If there is session data available + */ + private static sessionDataAvailable(): boolean { + let user = StorageService.getUserInfo(); + + return user !== undefined; } /** @@ -35,6 +47,10 @@ export class HomeComponent implements OnInit { sessionKey: '' }; + if(user.firebonkId === undefined || user.firstName === undefined || user.token === undefined) { + return; + } + let authenticatedUser = ApiService.performAuthentication(user); StorageService.setUserInfo(authenticatedUser); });