logout out automatically when session expires

This commit is contained in:
Wolfgang Hottgenroth 2021-09-12 13:26:08 +02:00
parent e3236b671d
commit a8296ee210
Signed by: wn
GPG Key ID: E49AF3B9EF6DD469
3 changed files with 22 additions and 5 deletions

View File

@ -41,6 +41,6 @@
<router-outlet></router-outlet>
<app-messages *ngIf="authenticated"></app-messages>
</mat-sidenav-content>
</mat-sidenav-container>

View File

@ -6,6 +6,7 @@ import jwt_decode from 'jwt-decode'
import { Observable, interval, Subject, Subscription } from 'rxjs'
import { map, takeWhile } from 'rxjs/operators'
import { authserviceBaseUrl, applicationId } from './config'
import { Router } from '@angular/router';
interface TokenTuple {
@ -24,8 +25,11 @@ export class TokenService {
private _expiryTime = new Subject<number>()
private subscription: Subscription
constructor(private http: HttpClient, private messageService: MessageService) {
}
constructor(
private http: HttpClient,
private router: Router,
private messageService: MessageService
) { }
checkAuthenticated(): boolean {
let result: boolean = false
@ -60,7 +64,15 @@ export class TokenService {
if (this.subscription && !this.subscription.closed) {
this.subscription.unsubscribe()
}
this.subscription = interval(1000).pipe(map(v => start - v)).pipe(takeWhile(v => v != 0)).subscribe(v => this._expiryTime.next(v))
this.subscription = interval(1000)
.pipe(map(v => start - v))
.pipe(takeWhile(v => v >= 0))
.subscribe((v) => {
this._expiryTime.next(v)
if (v == 0) {
this.router.navigate(['/logout'])
}
})
}
async login(login: string, password: string) : Promise<void> {

View File

@ -1,6 +1,11 @@
/* You can add global styles to this file, and also import other style files */
html, body { height: 100%; }
html, body {
height: 100%;
box-sizing: border-box;
margin: 0;
}
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
table {