agrege el front
This commit is contained in:
30
frontend/src/app/guards/auth.guard.ts
Normal file
30
frontend/src/app/guards/auth.guard.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import {AuthService} from "@auth0/auth0-angular";
|
||||
import {tap} from "rxjs/operators";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(private auth: AuthService,private router: Router) {
|
||||
}
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
|
||||
return this.auth.isAuthenticated$.pipe(
|
||||
tap( loggedIn =>{
|
||||
if(loggedIn){
|
||||
console.log('tiene permiso mi rey');
|
||||
|
||||
}else {
|
||||
console.log('no puede ingresar mi rey')
|
||||
this.router.navigate(['/public']);
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user