diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 64ed64e..35e73d0 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -42,6 +42,11 @@ export class AppComponent { this.isLoggedIn = this.firebaseService.getCurrentUserId(); } + /** + * Lifecycle hook that is called after the component has been initialized. + * + * Checks if the user is logged in by verifying the `isLoggedIn` property. + */ ngOnInit() { if (this.isLoggedIn === null) { this.checkPwResetRoute(); @@ -51,6 +56,10 @@ export class AppComponent { } } + /** + * Clears the local storage after a certain time period (12h) has + * passed since the last login. + */ checkAndClearLocalStorage() { const startTime = localStorage.getItem('sessionTimeJOIN'); @@ -64,6 +73,11 @@ export class AppComponent { } } + /** + * Listens to router events and checks if the current route is one of the + * allowed routes for password reset, registration, forgotten password, + * or login. If it is not, it navigates to the login page. + */ checkPwResetRoute() { this.router.events .pipe(filter((event) => event instanceof NavigationEnd)) @@ -78,6 +92,12 @@ export class AppComponent { }); } + /** + * Returns the first segment of the current URL or an empty string if it does not exist. + * + * @param urlTree The current URL tree. + * @returns The first segment of the current URL or an empty string if it does not exist. + */ private getFirstSegment(urlTree: any): string { return urlTree.root.children['primary']?.segments[0]?.path || ''; }