diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-04-20 00:12:42 +0000 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-04-20 00:12:42 +0000 |
commit | b814ef17d31dca80a3f23b3fbe4ce56885192a4c (patch) | |
tree | d7a297db46d57267b5516a8c20ee906dd39571ed /frontend/src/app/_services/auth.service.ts | |
parent | 9a480b28ac9b93dee082925b9cb4beef3244b135 (diff) | |
parent | e6d9e3fd2dcf83c90db8560e749544dfd9910d07 (diff) |
Merge branch 'dev' into 'master'
Merge master
See merge request igrannonica/neuronstellar!27
Diffstat (limited to 'frontend/src/app/_services/auth.service.ts')
-rw-r--r-- | frontend/src/app/_services/auth.service.ts | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts index 92cebe7f..9e3f9f2f 100644 --- a/frontend/src/app/_services/auth.service.ts +++ b/frontend/src/app/_services/auth.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { EventEmitter, Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { JwtHelperService } from '@auth0/angular-jwt'; import { CookieService } from 'ngx-cookie-service'; @@ -12,6 +12,8 @@ const jwtHelper = new JwtHelperService(); }) export class AuthService { + public loggedInEvent: EventEmitter<boolean> = new EventEmitter(); + shared = shared; constructor(private http: HttpClient, private cookie: CookieService) { } @@ -44,6 +46,7 @@ export class AuthService { enableAutoRefresh() { this.lastToken = this.cookie.get('token'); + clearTimeout(this.refresher); let exp = jwtHelper.getTokenExpirationDate(this.lastToken); if (!exp) { exp = new Date(); @@ -51,6 +54,7 @@ export class AuthService { var property = jwtHelper.decodeToken(this.cookie.get('token')); var username = property['name']; if (username != "") { + this.refresher = setTimeout(() => { this.http.post(`${Configuration.settings.apiURL}/auth/renewJwt`, {}, { headers: this.authHeader(), responseType: 'text' }).subscribe((response) => { this.authenticate(response); @@ -79,6 +83,7 @@ export class AuthService { } this.cookie.set('token', token, exp); this.updateUser(); + this.loggedInEvent.emit(true); } updateUser() { |