docs: add JSDoc comments to AuthGuard functions and move to dedicated folder

This commit is contained in:
Chneemann 2025-05-02 20:02:00 +02:00
parent 5f91d075ca
commit fa8a30e940
3 changed files with 8 additions and 19 deletions

View file

@ -3,7 +3,7 @@ import { ImprintComponent } from './shared/components/legal-information/imprint/
import { PrivacyPolicyComponent } from './shared/components/legal-information/privacy-policy/privacy-policy.component'; import { PrivacyPolicyComponent } from './shared/components/legal-information/privacy-policy/privacy-policy.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { AuthComponent } from './components/auth/auth.component'; import { AuthComponent } from './components/auth/auth.component';
import { AuthGuard } from './auth.guard'; import { AuthGuard } from './guards/auth.guard';
export const routes: Routes = [ export const routes: Routes = [
{ path: '', component: AuthComponent }, { path: '', component: AuthComponent },

View file

@ -1,17 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { CanActivateFn } from '@angular/router';
import { authGuard } from './auth.guard';
describe('authGuard', () => {
const executeGuard: CanActivateFn = (...guardParameters) =>
TestBed.runInInjectionContext(() => authGuard(...guardParameters));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});

View file

@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; import { map, catchError } from 'rxjs/operators';
import { AuthService } from './services/auth.service'; import { AuthService } from '../services/auth.service';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -10,6 +10,12 @@ import { AuthService } from './services/auth.service';
export class AuthGuard { export class AuthGuard {
constructor(private authService: AuthService, private router: Router) {} constructor(private authService: AuthService, private router: Router) {}
/**
* Determines if the route can be activated by checking if the user is authenticated.
*
* @returns An Observable, Promise, or boolean indicating whether the route can be activated.
* If the user is authenticated, returns true; otherwise, navigates to the root path and returns false.
*/
canActivate(): Observable<boolean> | Promise<boolean> | boolean { canActivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.authService.checkAuthUser().pipe( return this.authService.checkAuthUser().pipe(
map((isAuthenticated) => { map((isAuthenticated) => {