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.
you can share screenshot of you code where’re you using localStorage with setItem and getItem?
Or with the Storage
Try with Async and Await.
Run this comand.
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
import { Storage } from '@ionic/storage';
constructor(private storage: Storage) { }
And try this…
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'])
}
}
I had a similar problem. My solution is like that (in app.module):
IonicStorageModule.forRoot({
name: '_myDb',
driverOrder: ['localstorage']
}),
2 Likes
Actually async process run fine with browser but it doesn’t work with mobile
Try this.
IonicStorageModule.forRoot({
name: '_mydb',
driverOrder: ['indexeddb', 'sqlite', 'websql'],
}),
1 Like
I had trouble when i used this on device: driverOrder: [‘indexeddb’, ‘sqlite’, ‘websql’]
When i changed it to driverOrder: [‘localstorage’] it worked well.
How can I do the same on ion react?
1 Like