0.0.2 • Published 5 years ago

ng-sess-timeout v0.0.2

Weekly downloads
8
License
-
Repository
-
Last release
5 years ago

ng-sess-timeout

About

For implementing the session timeout login on front end. I have tried to keep it very simple but it will serve the purpose..

========

Authored by Naveen Shrinag mail- naveen.shrinag8787@gmail.com

Requirements

  • Angular 5 or later.

Getting Started (Example)

  1. installation : npm install ng-sess-timeout

  2. import NgTimeoutModule on your app.module.ts

    .... import {NgTimeoutModule} from 'ng-sess-timeout';

    @NgModule({ declarations: AppComponent , imports: BrowserModule, NgTimeoutModule, ... , providers: [], bootstrap: AppComponent }) export class AppModule { }

  3. import {NgTimeout} from 'ng-sess-timeout'; // import to the component where you want to use this ....

    export class AppComponent {

    constructor(private sessTimer:NgTimeout) {
        
    }
    
    ngOnInit() {
    
        // set the session timeout time in minutes
        this.sessTimer.timer = 1;
    
        // subscribe to timeExpired to know if session has exprired. returns true (session expired) and false.
        this.sessTimer.timeExpired.subscribe((value)=> {
        console.log(value);
        })
    
        // suscribe to timeLeft to know how much time (in seconds) is left before session timeout
    
        this.sessTimer.timeLeft.subscribe((time)=> {
        console.log(time);
        })
    
        // to stop the timer but any user movement will again trigger it.
        this.sessTimer.stop(); 
    
        // use to reset the timer
    
        this.sessTimer.reset();
    
        // call to stop method on ngDestroy and unsubscribe, failing which can lead to unexpected errors.
    }

    }