From 03177959b3e50b6f4e80045a7e545938f56e84fa Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sat, 30 Apr 2022 18:56:46 +0200 Subject: Omoguceno da Guest ne gubi token na refreshu. --- frontend/src/app/_services/auth.service.ts | 11 +++++++++++ frontend/src/app/app.component.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'frontend/src') diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts index dd46615d..845cb3f5 100644 --- a/frontend/src/app/_services/auth.service.ts +++ b/frontend/src/app/_services/auth.service.ts @@ -106,4 +106,15 @@ export class AuthService { authHeader() { return new HttpHeaders().set("Authorization", "Bearer " + this.cookie.get('token')); } + alreadyGuest(){ + if(this.cookie.check('token')){ + const token = this.cookie.get('token'); + const decodedToken = jwtHelper.decodeToken(token); + if(decodedToken.role=="Guest") + return true; + } + return false; + } + + } diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index f9bc2726..e301b46f 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -40,7 +40,8 @@ export class AppComponent implements OnInit, AfterViewInit { } }); if (!this.authService.isAuthenticated()) { - this.authService.addGuestToken(); + if(!this.authService.alreadyGuest()) + this.authService.addGuestToken(); } this.signalRService.startConnection(); //this.startHttpRequest(); -- cgit v1.2.3