Ajout d'un appel pour check la

validité du token
This commit is contained in:
Sébastien André
2020-03-21 17:18:31 +01:00
parent 77c545499d
commit 8c6a187ff0
2 changed files with 26 additions and 11 deletions
@@ -1,15 +1,23 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthenticationService } from './authentication.service';
import { Injectable } from "@angular/core";
import {
CanActivate,
Router,
ActivatedRouteSnapshot,
RouterStateSnapshot
} from "@angular/router";
import { AuthenticationService } from "./authentication.service";
@Injectable({ providedIn: 'root' })
@Injectable({ providedIn: "root" })
export class AuthGuardService implements CanActivate {
constructor(
private router: Router,
private authenticationService: AuthenticationService
) { }
) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
public canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
) {
const currentUser = this.authenticationService.currentUserValue;
if (currentUser) {
// logged in so return true
@@ -17,7 +25,7 @@ export class AuthGuardService implements CanActivate {
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
this.router.navigate(["/login"], { queryParams: { returnUrl: state.url } });
return false;
}
}