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); });