Add documentation to the guards module.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// Core imports
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
// Application imports
|
||||
import { AuthGuard } from '@app/_guards/auth.guard';
|
||||
|
||||
describe('AuthGuard', () => {
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
// Core imports
|
||||
import { Injectable } from '@angular/core';
|
||||
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router} from '@angular/router';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
|
||||
// Third party imports
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Auth guard implementation.
|
||||
* Dictates access to routes depending on the authentication status.
|
||||
*
|
||||
* @implements CanActivate
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
/**
|
||||
* Instantiates the auth guard class.
|
||||
*
|
||||
* @param router - A service that provides navigation among views and URL manipulation capabilities.
|
||||
*/
|
||||
constructor(private router: Router) {}
|
||||
|
||||
/**
|
||||
* Returns whether navigation to a specific route is acceptable.
|
||||
* Checks if the user has uploaded a private key.
|
||||
*
|
||||
* @param route - Contains the information about a route associated with a component loaded in an outlet at a particular moment in time.
|
||||
* ActivatedRouteSnapshot can also be used to traverse the router state tree.
|
||||
* @param state - Represents the state of the router at a moment in time.
|
||||
* @returns true - If there is an active private key in the user's localStorage.
|
||||
*/
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Core imports
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
// Application imports
|
||||
import { RoleGuard } from '@app/_guards/role.guard';
|
||||
|
||||
describe('RoleGuard', () => {
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
// Core imports
|
||||
import { Injectable } from '@angular/core';
|
||||
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router} from '@angular/router';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
|
||||
// Third party imports
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Role guard implementation.
|
||||
* Dictates access to routes depending on the user's role.
|
||||
*
|
||||
* @implements CanActivate
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoleGuard implements CanActivate {
|
||||
|
||||
/**
|
||||
* Instantiates the role guard class.
|
||||
*
|
||||
* @param router - A service that provides navigation among views and URL manipulation capabilities.
|
||||
*/
|
||||
constructor(private router: Router) {}
|
||||
|
||||
/**
|
||||
* Returns whether navigation to a specific route is acceptable.
|
||||
* Checks if the user has the required role to access the route.
|
||||
*
|
||||
* @param route - Contains the information about a route associated with a component loaded in an outlet at a particular moment in time.
|
||||
* ActivatedRouteSnapshot can also be used to traverse the router state tree.
|
||||
* @param state - Represents the state of the router at a moment in time.
|
||||
* @returns true - If the user's role matches with accepted roles.
|
||||
*/
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
|
||||
Reference in New Issue
Block a user