Auth Guard in Angular 2+
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { AuthServicesService } from './auth-services.service';
import {Router} from '@angular/router';
import { HttpClient, HttpHeaders } from "@angular/common/http";
import {map} from 'rxjs/operators';
import { AllServiceService } from "./all-services/all-service.service";
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(
private router:Router,
private auth: AuthServicesService,
private myRoute: Router,
private http:HttpClient,
private manage:AllServiceService,
){}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if(this.auth.isLoggednIn()){
return true;
}
else {
return false;
}
}
}
Comments
Post a Comment