docs: add JSDoc comments to app.component.ts

This commit is contained in:
Chneemann 2024-11-16 18:19:24 +01:00
parent 33a9b4e566
commit 5949934b0d

View file

@ -42,6 +42,11 @@ export class AppComponent {
this.isLoggedIn = this.firebaseService.getCurrentUserId(); 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() { ngOnInit() {
if (this.isLoggedIn === null) { if (this.isLoggedIn === null) {
this.checkPwResetRoute(); 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() { checkAndClearLocalStorage() {
const startTime = localStorage.getItem('sessionTimeJOIN'); 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() { checkPwResetRoute() {
this.router.events this.router.events
.pipe(filter((event) => event instanceof NavigationEnd)) .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 { private getFirstSegment(urlTree: any): string {
return urlTree.root.children['primary']?.segments[0]?.path || ''; return urlTree.root.children['primary']?.segments[0]?.path || '';
} }