diff --git a/src/app/pages/admin-page/admin-page.component.ts b/src/app/pages/admin-page/admin-page.component.ts
index e431721..0595138 100644
--- a/src/app/pages/admin-page/admin-page.component.ts
+++ b/src/app/pages/admin-page/admin-page.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit } from '@angular/core';
+import { Component, EventEmitter, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { ApiBackService } from 'src/app/services/api-back.service';
@@ -11,6 +11,7 @@ import { Restaurant } from '../models/restaurant';
})
export class AdminPageComponent implements OnInit {
+ sendId = new EventEmitter
();
constructor( ) {
@@ -18,6 +19,9 @@ export class AdminPageComponent implements OnInit {
ngOnInit(): void {
}
+ sendIdRestau(idRestau : number){
+ this.sendId.emit(idRestau);
+ }
}
diff --git a/src/app/services/api-back.service.ts b/src/app/services/api-back.service.ts
index 7e37e82..b44cf59 100644
--- a/src/app/services/api-back.service.ts
+++ b/src/app/services/api-back.service.ts
@@ -1,4 +1,4 @@
-import { Injectable, Input } from '@angular/core';
+import { EventEmitter, Injectable, Input } from '@angular/core';
import { Observable, of, Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@@ -15,6 +15,7 @@ export class ApiBackService {
public restoFilter: any[];
public routeParam?: string;
@Input() restaurant: any;
+ public restauAModif = new EventEmitter();
constructor(private httpClient: HttpClient) {
this.restoFilter = [];
@@ -70,4 +71,10 @@ export class ApiBackService {
return this.httpClient.get(`${environment.apiUrl}/user/${id}`);
}
+
+ public idRestauAModifier(restau:Restaurant): void {
+
+ this.restauAModif.emit(restau);
+ }
}
+
diff --git a/src/app/services/auth.guard.ts b/src/app/services/auth.guard.ts
index f16c965..6001ce1 100644
--- a/src/app/services/auth.guard.ts
+++ b/src/app/services/auth.guard.ts
@@ -11,6 +11,7 @@ import { TokenService } from './token.service';
})
export class AuthGuard implements CanActivate {
private tokenKey: string;
+
constructor(private router: Router, private tokenService : TokenService){
this.tokenKey = environment.tokenKey;
}
@@ -23,6 +24,9 @@ export class AuthGuard implements CanActivate {
if(token) {
const decodedToken = jwt_decode(token);
+
+ // TODO boucle sur le ['auth'] pour controler le role et en fonction de ca renvoyer true ou false ac redirection page403
+
console.log('decodedToken : ', decodedToken);
@@ -31,7 +35,7 @@ export class AuthGuard implements CanActivate {
const dateExp = new Date(decodedToken.exp * 1000);
if(new Date() >= dateExp) {
// le token a expiré, je n'autorise pas l'accès
- this.tokenService.destroyToken();
+ this.tokenService.destroyToken(this.tokenKey);
this.router.navigate(['signin']);
return false;
}
diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts
index b649e4f..c1ed182 100644
--- a/src/app/services/auth.service.ts
+++ b/src/app/services/auth.service.ts
@@ -50,6 +50,7 @@ export class AuthService {
console.log('Service : ', x.token);
// Modification à faire ici
localStorage.setItem(this.tokenKey, x.token);
+ //localStorage.setItem('ROLE', "ROLE_READER");
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
})
);
diff --git a/src/app/services/token.service.ts b/src/app/services/token.service.ts
index 0529b5d..4d376de 100644
--- a/src/app/services/token.service.ts
+++ b/src/app/services/token.service.ts
@@ -33,7 +33,8 @@ export class TokenService {
}
- public destroyToken(): void {
- localStorage.removeItem(this.tokenKey);
+ public destroyToken(tokenKey : string): void {
+ localStorage.removeItem(tokenKey);
+ localStorage.removeItem('ROLE');
}
}