Skip to content

Commit 40c4bad

Browse files
committed
fix: ensure login is called during initialization and improve error handling in IterableAppProvider
1 parent 5df923f commit 40c4bad

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

example/src/hooks/useIterableApp.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export const IterableAppProvider: FunctionComponent<
141141

142142
const initialize = useCallback(
143143
(navigation: Navigation) => {
144+
login();
145+
144146
const config = new IterableConfig();
145147

146148
config.inAppDisplayInterval = 1.0; // Min gap between in-apps. No need to set this in production.
@@ -219,33 +221,31 @@ export const IterableAppProvider: FunctionComponent<
219221
console.log('🚀 > IterableAppProvider > isSuccessful:', isSuccessful);
220222

221223
if (!isSuccessful) {
222-
// return Promise.reject('`Iterable.initialize` failed');
223-
throw new Error('`Iterable.initialize` failed');
224+
return Promise.reject('`Iterable.initialize` failed');
224225
} else if (getUserId()) {
225226
login();
226227
}
227228

228229
return isSuccessful;
229230
})
230231
.catch((err) => {
231-
console.log(`🚀 > IterableAppProvider > err:`, err);
232-
// console.error(
233-
// '`Iterable.initialize` failed with the following error',
234-
// err
235-
// );
236-
// setIsInitialized(false);
237-
// setLoginInProgress(false);
238-
// return Promise.reject(err);
232+
console.error(
233+
'`Iterable.initialize` failed with the following error',
234+
err
235+
);
236+
setIsInitialized(false);
237+
setLoginInProgress(false);
238+
return Promise.reject(err);
239239
})
240240
.finally(() => {
241241
// For some reason, ios is throwing an error on initialize.
242242
// To temporarily fix this, we're using the finally block to login.
243243
// MOB-10419: Find out why initialize is throwing an error on ios
244-
// setIsInitialized(true);
245-
// if (getUserId()) {
246-
// login();
247-
// }
248-
// return Promise.resolve(true);
244+
setIsInitialized(true);
245+
if (getUserId()) {
246+
login();
247+
}
248+
return Promise.resolve(true);
249249
});
250250
},
251251
[apiKey, getUserId, login, getJwtToken]

0 commit comments

Comments
 (0)