docs: add JSDoc comments to AuthGuard functions and move to dedicated folder
This commit is contained in:
parent
5f91d075ca
commit
fa8a30e940
3 changed files with 8 additions and 19 deletions
|
|
@ -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 { HomeComponent } from './components/home/home.component';
|
||||
import { AuthComponent } from './components/auth/auth.component';
|
||||
import { AuthGuard } from './auth.guard';
|
||||
import { AuthGuard } from './guards/auth.guard';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: '', component: AuthComponent },
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|||
import { Router } from '@angular/router';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
|
|
@ -10,6 +10,12 @@ import { AuthService } from './services/auth.service';
|
|||
export class AuthGuard {
|
||||
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 {
|
||||
return this.authService.checkAuthUser().pipe(
|
||||
map((isAuthenticated) => {
|
||||
Loading…
Reference in a new issue