Session idle timeout with logout implementation

This commit is contained in:
Jose Alberto Hernandez
2024-04-16 19:43:17 -06:00
committed by Jose Alberto Hernandez
parent caf3d39719
commit 29d3d08e88
28 changed files with 189 additions and 6 deletions
@@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import { environment } from 'environments/environment';
import { interval, merge, fromEvent, Observable} from 'rxjs';
import { takeUntil, repeat, map} from 'rxjs/operators';
/**
* Idle timeout service used to track idle user
*/
@Injectable({
providedIn: 'root'
})
export class IdleTimeoutService {
// max timeout for an idle user
readonly timeoutDelay = environment.session.timeout.idleTimeout || 300000; // 5 minutes
// observable timeout
readonly $onSessionTimeout: Observable<void>;
constructor() {
const events = ['mousemove', 'keydown', 'wheel', 'mousedown', 'scroll'];
const $signal = merge(...events.map(eventName => fromEvent(document, eventName)));
this.$onSessionTimeout = interval(this.timeoutDelay).pipe(
takeUntil($signal),
map(() => undefined),
repeat()
);
}
}