Session idle timeout with logout implementation
This commit is contained in:
committed by
Jose Alberto Hernandez
parent
caf3d39719
commit
29d3d08e88
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user