# In Ionic4 Data storage and local storage is not working in the phone

**URL:** <https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364>\
**Category:** Ionic Framework\
**Created:** [December 26, 2019, 1:16am UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364 "2019-12-26T01:16:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![manimaranselvaraj](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@manimaranselvaraj](https://forum.ionicframework.com/u/manimaranselvaraj)\
**Post date:** [December 26, 2019, 1:16am UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/1 "2019-12-26T01:16:44Z")

</div>

For reference:In Ionic 4 while i login as user i store a token in local storage and Data storage and using that token for several process like session handling and adding products. I check those process in browser it’s actually works but when build app as apk using ionic cordova build android… local storage and data storage is not working on the build apk.

---

<div class="post-metadata">

**Author:** ![crmontiel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/crmontiel/32/127900_2.png) [@crmontiel](https://forum.ionicframework.com/u/crmontiel)\
**Post date:** [December 26, 2019, 5:37pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/2 "2019-12-26T17:37:13Z")

</div>

you can share screenshot of you code where’re you using localStorage with setItem and getItem?  
Or with the Storage

---

<div class="post-metadata">

**Author:** ![manimaranselvaraj](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@manimaranselvaraj](https://forum.ionicframework.com/u/manimaranselvaraj)\
**Post date:** [December 28, 2019, 1:09pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/3 "2019-12-28T13:09:58Z")

</div>

![code ionic](https://global.discourse-cdn.com/ionicframework/original/3X/1/f/1f8d571079f1910aa84c22cdd6fb6ada82fd3ada.png) ![storage](https://global.discourse-cdn.com/ionicframework/original/3X/0/3/039aff7e2cc29af7c91c55c4526b99d72f2c6e1f.png)  
 ![appmodule](https://global.discourse-cdn.com/ionicframework/original/3X/d/5/d52256d697a96d8f0529bdd70acb0a9a74585d05.png)  
this is screenshot of my coding after i build those a package as apk its not working!

---

<div class="post-metadata">

**Author:** ![crmontiel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/crmontiel/32/127900_2.png) [@crmontiel](https://forum.ionicframework.com/u/crmontiel)\
**Post date:** [December 28, 2019, 5:36pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/4 "2019-12-28T17:36:04Z")

</div>

Try with Async and Await.  
Run this comand.

```auto
1: i onic cordova plugin add cordova-sqlite-storage
2: npm install --save @ionic/stora

```

Import the module of storage in you app.module and on you component where you’re using storage declare the variable in the constructorv

```auto
import { Storage } from '@ionic/storage';

constructor(private storage: Storage) { }

```

And try this…

```auto
async backDashboard(){
	this.essionexp();

	let token= await this.storage.get('token')

	if(String(token)!='null' || String(token)!='undefined'){
		this.navCtrl.navigateBack(['/dashboard'])
	}else{
		this.navCtrl.navigateBack(['/login'])
	}
}

```

---

<div class="post-metadata">

**Author:** ![LacOniC](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/laconic/32/130566_2.png) [@LacOniC](https://forum.ionicframework.com/u/LacOniC)\
**Post date:** [December 28, 2019, 9:09pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/5 "2019-12-28T21:09:34Z")

</div>

I had a similar problem. My solution is like that (in app.module):

```
IonicStorageModule.forRoot({
  name: '_myDb',
  driverOrder: ['localstorage']
}),
```

---

<div class="post-metadata">

**Author:** ![manimaranselvaraj](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@manimaranselvaraj](https://forum.ionicframework.com/u/manimaranselvaraj)\
**Post date:** [December 30, 2019, 3:47am UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/6 "2019-12-30T03:47:55Z")

</div>

Actually async process run fine with browser but it doesn’t work with mobile

---

<div class="post-metadata">

**Author:** ![crmontiel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/crmontiel/32/127900_2.png) [@crmontiel](https://forum.ionicframework.com/u/crmontiel)\
**Post date:** [December 30, 2019, 1:32pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/7 "2019-12-30T13:32:10Z")

</div>

Try this.

```auto
  IonicStorageModule.forRoot({
      name: '_mydb',
      driverOrder: ['indexeddb', 'sqlite', 'websql'],

    }),

```

---

<div class="post-metadata">

**Author:** ![LacOniC](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/laconic/32/130566_2.png) [@LacOniC](https://forum.ionicframework.com/u/LacOniC)\
**Post date:** [January 4, 2020, 12:57pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/8 "2020-01-04T12:57:19Z")

</div>

I had trouble when i used this on device: driverOrder: [‘indexeddb’, ‘sqlite’, ‘websql’]

When i changed it to driverOrder: [‘localstorage’] it worked well. 😕

---

<div class="post-metadata">

**Author:** ![ajro](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@ajro](https://forum.ionicframework.com/u/ajro)\
**Post date:** [September 11, 2020, 9:17pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/9 "2020-09-11T21:17:35Z")

</div>

> [@LacOniC](#):
>
> ```auto
> IonicStorageModule.forRoot({
> name: '_myDb',
> driverOrder: ['localstorage']
> }),
> 
> ```

How can I do the same on ion react?

---

<div class="post-metadata">

**Author:** ![skiod](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@skiod](https://forum.ionicframework.com/u/skiod)\
**Post date:** [February 25, 2021, 8:30pm UTC](https://forum.ionicframework.com/t/in-ionic4-data-storage-and-local-storage-is-not-working-in-the-phone/180364/10 "2021-02-25T20:30:59Z")

</div>

I’m working with ionic vuejs - capacitor

and i tried this one, it throw an error

 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/4/c/4c1198e9e2ae6c02b383123b4c3413d735142255.png)

could you help please im trying to save data locally with no success …
