Created
March 18, 2021 22:25
-
-
Save tiagolpadua/183c60f803616d2107f6631501e3332a to your computer and use it in GitHub Desktop.
cmail\src\app\guards\auth2.guard.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { CanActivate, Router } from '@angular/router'; | |
| import { catchError, map } from 'rxjs/operators'; | |
| import { LoginService } from '../services/login.service'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class Auth2Guard implements CanActivate { | |
| constructor(private roteador: Router, private loginService: LoginService) { } | |
| canActivate() { | |
| return this.loginService.validaToken() | |
| .pipe( | |
| map(response => response.ok), | |
| catchError(() => { | |
| localStorage.removeItem('cmail-token'); | |
| this.roteador.navigate(['login']); | |
| return [false]; | |
| }) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment