File

src/app/_guards/auth.guard.ts

Index

Methods

Constructor

constructor(router: Router)
Parameters :
Name Type Optional
router Router No

Methods

canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
Parameters :
Name Type Optional
route ActivatedRouteSnapshot No
state RouterStateSnapshot No
Returns : Observable | Promise | boolean | UrlTree
import { Injectable } from '@angular/core';
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router} from '@angular/router';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate {

  constructor(private router: Router) {}

  canActivate(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
    if (localStorage.getItem(btoa('CICADA_PRIVATE_KEY'))) {
      return true;
    }
    this.router.navigate(['/auth']);
    return false;
  }

}

result-matching ""

    No results matching ""