I am using Ionic 2 to build a mobile app. The app uses Intercom (https://developers.intercom.com/docs/cordova-phonegap-installation - https://github.com/intercom/intercom-cordova).
As per the integration instructions I am registering unidentified users on app boot within the app.component.ts file. This works fine.
In order to identify registered users I need to pull a number of items from storage (user ID and email address). This uses a promise, so is asynchronous. When doing this Intercom does not register the user. If I just call the user normally with hard-coded values, not querying storage, then it works fine.
Storage on the device is very quick, and I only need to do this once on app boot during the splash screen load, so I'm happy to have the app wait while the promise runs. Is this possible? Or, am I going about this all wrong?
My code from app.component.ts` below:
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
// This works
intercom.registerUnidentifiedUser({});
// This also works
intercom.registerIdentifiedUser({
userId: '987654321',
email: 'foobar@example.com'
});
// This does not work
storage.get('user_id').then((user_id) => {
storage.get('email').then((email) => {
intercom.registerIdentifiedUser({
userId: user_id,
email: email
});
});
});
});
Because Intercom is a native library I need to test on a device, so I have no error logs. If I place console.logs inside the storage promises I can see the appropriate values, so it isn't that.
To reiterate my question here:
Do I need to prevent my storage call from being asynchronous, and if so, how?
Or, am I approaching this the wrong way? The Intercom docs clearly state that it's a case of checking if the user is logged in and then calling registerUnidentifiedUser or registerIdentifiedUser appropriately, and I believe I'm following best practice by storing user data in storage.