Where and how to save and get data fast in device for login and next updates?


#1

I’ve loading native UDI and Token which are saved by Ionic Native Storage correctly in Loginpage after SMS verification.

But the problem is on mobile device the NativeStorage.getItem return result after moving to login page and then moving to DashboardPage after a minuet.

How can I solve this and how to speedup this process? Also this data should be stored safely for use in next app updates.(avoiding each time app updates usere register or login again and again.)

app.componnent.ts

export class Myapp {
    @ViewChild(Nav) nav: Nav;
    rootPage: any = FirstPage;
    constructor(private NativeStorage: NativeStorage, private platform: Platform) {
        this.initializeApp();
    }
    initializeApp() {
        console.log('appcomponent');
        this.platform.ready().then(() => {
            console.log('ready');
            NativeStorage.getItem('UserDeviceauth')
                .then(
                data => {
                    console.log(data);
                    console.log(data.UDI, data.Token);
                    if ( data.UDI == 'undefined' || data.Token == 'undefined') {
                        this.nav.setRoot(LoginPage)
                    }
                    else {
                        this.nav.setRoot(DashboardPage, data);
                    }

                });
        });
    }
    openPage(page) {
        this.nav.setRoot(page.component);
    }
}

#2

The [quote=“rsa, post:1, topic:89367”]
Ionic Native Storage
[/quote]
you talk about is Ionic Native with Native Storage plugin at https://ionicframework.com/docs/native/native-storage/?

What exactly is happening? I don’t understand the “But the problem is…” sentence.


#3

I will describe it by screen shot.

as you can see In device log. however initialize method in app.component.ts fire first but the same time goes to firs page and in that page also ionViewDidLoad method fires in first page I try to do NativeStorage.getItem but ‘t’ is empty.

console log shows in first page UDI and Token are undefined now rout to login page and yellow box shows page is loaded because it got a new UDI then in app.component.ts NativeStorage.getItem succeed and got the saved data and in green box dashboard is loaded with UDI and Token.