diff --git a/ui/hv2-ui/src/app/navigation/navigation.component.html b/ui/hv2-ui/src/app/navigation/navigation.component.html index 4f76fe5..32f1880 100644 --- a/ui/hv2-ui/src/app/navigation/navigation.component.html +++ b/ui/hv2-ui/src/app/navigation/navigation.component.html @@ -28,6 +28,7 @@ Nober Grundbesitz GbR Hausverwaltung + Expires in: {{expiresIn}} seconds GITTAGVERSION Login Logout diff --git a/ui/hv2-ui/src/app/navigation/navigation.component.ts b/ui/hv2-ui/src/app/navigation/navigation.component.ts index 11970ae..13eb4b0 100644 --- a/ui/hv2-ui/src/app/navigation/navigation.component.ts +++ b/ui/hv2-ui/src/app/navigation/navigation.component.ts @@ -5,6 +5,8 @@ import { map, shareReplay } from 'rxjs/operators'; import { TokenService } from '../token.service'; import { NavigationEnd, Router } from '@angular/router'; + + @Component({ selector: 'app-navigation', templateUrl: './navigation.component.html', @@ -13,6 +15,7 @@ import { NavigationEnd, Router } from '@angular/router'; export class NavigationComponent { public authenticated: boolean + expiresIn: number isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) .pipe( @@ -33,6 +36,7 @@ export class NavigationComponent { ngOnInit() { this.authenticated = this.tokenService.checkAuthenticated() + this.expiresIn = 600 } } diff --git a/ui/hv2-ui/src/app/token.service.ts b/ui/hv2-ui/src/app/token.service.ts index bd3aa7c..23e88cf 100644 --- a/ui/hv2-ui/src/app/token.service.ts +++ b/ui/hv2-ui/src/app/token.service.ts @@ -3,6 +3,8 @@ import { MessageService } from './message.service'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { UserCreds } from './userCreds' import jwt_decode from 'jwt-decode' +import { Observable } from 'rxjs'; +import { ComplexOuterSubscriber } from 'rxjs/internal/innerSubscribe'; @@ -45,7 +47,7 @@ export class TokenService { } async login(login: string, password: string) { - this.messageService.add(`TokenService: trying to login and obtain token`); + this.messageService.add(`TokenService: trying to login and obtain token`) const userCreds : UserCreds = { "application": "hv2", "login": login, @@ -62,7 +64,7 @@ export class TokenService { async refresh() { try { - this.messageService.add(`TokenService: trying to refresh tokens`); + this.messageService.add(`TokenService: trying to refresh tokens`) const refreshToken = localStorage.getItem(TokenService.Id_RefreshToken_Key) const tokenTuple: TokenTuple = await this.http.post( "https://authservice.hottis.de/refresh", @@ -79,5 +81,23 @@ export class TokenService { } } + expiryUpdate() : Observable { + const exUp = new Observable((observer) => { + let i = 600 + + while (i != 0) { + observer.next(i) + i -= 1 + await new Promise(f => setTimeout(f, 1000)) + } + observer.complete() + + return { + unsubscribe() { + } + } + }) + return exUp + } }