Where to temporary store a variable so that it can not be deleted when you refresh a page

I’m doing a school project. I’m beginner to Ionic + Angular.

Once a user logs in my PWA, the user’s email is assigned as a variable in a .service file called ‘CRUD.service.ts’. I use it so that whenever a logged in user go to any page, I have a record of their email.

But the problem is that when the user refreshes the page in the browser or navigate back and forward, the variables in my ‘CRUD.service.ts’ are cleared so I do not have record of their email anymore.

I need it so that even if they refresh the page, their email is still stored somewhere but it will only be cleared when they logout.

Hi @jefredallan!
You may use Native Storage to do that.
So, you do a setItem and a getItem, to store and retrieve the data you want.

import { NativeStorage } from '@ionic-enterprise/nativestorage/ngx';

constructor(private nativeStorage: NativeStorage) { }

...

this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
  .then(
    () => console.log('Stored item!'),
    error => console.error('Error storing item', error)
  );

this.nativeStorage.getItem('myitem')
  .then(
    data => console.log(data),
    error => console.error(error)
  );

You can see the Docs:

does this support PWA? thanks.

I’ve never used any of the enterprise stuff. What does that offer us over good old ionic-storage?

I used ionic-storage instead and it worked. Enterprise cannot be installed for me for some reason.

I think you have to pay for it.

OMG! It’s my fault, didn’t see that it was enterprise stuffs… :sweat_smile:

you can easily use ionic local storage for description and learn u can go to below link…if u can not understand it , you can send me you`re pages to help u… good luck