moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
315 stars 128 forks source link

How to store data(ng2Idle.main.expiry) in sessionStorage Instead of localStorage?? #104

Open madhujsmg opened 6 years ago

madhujsmg commented 6 years ago

I tried to find solution in ng2-idle documents but am not finding satisfactory information ,

The issue with if one browser window is active and other window timeout is not happening

is there any way to store data in session instead of localStorage???

KellenHe commented 4 years ago

Hi @madhujsmg do you find the solution ? I also want to use session instead of localStorage

adampicker commented 3 years ago

I would really appreciate the solution

elaihau commented 3 years ago

Implement your own provider for storing the data:

import { LocalStorage } from '@ng-idle/core';

export class MyStorage extends LocalStorage {
    constructor() {
        super();
        if (sessionStorage) {
          this['storage'] = sessionStorage;
        }
    }
}

and in your module:

import { LocalStorage } from '@ng-idle/core';
import { MyStorage } from './my-storage';

@NgModule({
  providers: [
    { provide: LocalStorage, useClass: MyStorage },
  ],
})

My personal suggestion to the maintainer of this repo is making the private storage a protected variable in the LocalStorage class.