ng2-idle icon indicating copy to clipboard operation
ng2-idle copied to clipboard

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

Open madhujsmg opened this issue 7 years ago • 3 comments

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???

madhujsmg avatar Jun 27 '18 12:06 madhujsmg

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

KellenHe avatar Jul 01 '20 08:07 KellenHe

I would really appreciate the solution

adampicker avatar Oct 27 '20 14:10 adampicker

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.

elaihau avatar Nov 02 '20 13:11 elaihau