UNPKG

session-expiration-alert

Version:

An Angular module to time session expiration. When user session idle time reaches a threshold, then pop up a modal dialog to let user choose to continue session or log out the system. When user session is expired, timer will stop and user will be logged o

90 lines (83 loc) 3.53 kB
import * as _angular_core from '@angular/core'; import { InjectionToken, Type, Provider, EnvironmentProviders, OnInit, OnChanges, OnDestroy, SimpleChanges } from '@angular/core'; import { HttpRequest, HttpHandlerFn, HttpEvent } from '@angular/common/http'; import { Observable } from 'rxjs'; declare const SEA_INTERRUPT_SERVICE: InjectionToken<SessionInterruptService>; interface SessionInterruptService { /** * Method to refresh session cookie. Normally, this method issue a quick API call to server. * * @memberof SessionInterruptService */ continueSession(): void; /** * Method to remove session cookie. Normally, this method redirect to website logout endpoint. * * @memberof SessionInterruptService */ stopSession(): void; /** * Method to handle expiration event. Can be empty. */ onExpire(): void; } interface SessionExpirationConfig { totalMinutes: number; } declare const ConfigToken: InjectionToken<SessionExpirationConfig>; declare function provideSessionExpirationServices(interrupter: Type<SessionInterruptService>, config?: SessionExpirationConfig): (Provider | EnvironmentProviders)[]; declare function sessionTimerHttpInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>>; declare class SessionTimerService { private readonly config; private readonly _timeoutSeconds; private timerSubscription?; private timer; private _remainSeconds; /** * Observable to get session remaining time (in seconds). * * Subscribers need to unsubscribe to it before hosting element is destroyed. * * @memberof SessionTimerService */ remainSeconds$: Observable<number>; startTimer(): void; stopTimer(): void; resetTimer(): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration<SessionTimerService, never>; static ɵprov: _angular_core.ɵɵInjectableDeclaration<SessionTimerService>; } declare class SessionExpirationAlert implements OnInit, OnChanges, OnDestroy { /** * Should start the timer or not. Usually, you can set it to true if a user is authenticated. */ startTimer: _angular_core.InputSignal<boolean>; /** * Count down seconds. */ alertAt: _angular_core.InputSignal<number>; showModal: _angular_core.WritableSignal<boolean>; expired: _angular_core.WritableSignal<boolean>; private sessionTimerSubscription?; private el; private sessionInterrupter; sessionTimer: SessionTimerService; ngOnInit(): void; ngOnChanges(changes: SimpleChanges<{ startTimer: boolean; }>): void; private trackSessionTime; continue(): void; logout(): void; open(): void; close(): void; cleanUp(): void; reload(): void; ngOnDestroy(): void; handleTabKey(event: Event): void; handleShiftTabKey(event: Event): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration<SessionExpirationAlert, never>; static ɵcmp: _angular_core.ɵɵComponentDeclaration<SessionExpirationAlert, "session-expiration-alert", never, { "startTimer": { "alias": "startTimer"; "required": false; "isSignal": true; }; "alertAt": { "alias": "alertAt"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>; } export { ConfigToken, SEA_INTERRUPT_SERVICE, SessionExpirationAlert, SessionTimerService, provideSessionExpirationServices, sessionTimerHttpInterceptor }; export type { SessionExpirationConfig, SessionInterruptService };