Skip to content

Commit 5810a0a

Browse files
committed
feat: improve JWT error handling and enhance IterableConfig with additional flags
1 parent 7fde4e7 commit 5810a0a

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/core/classes/Iterable.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ export class Iterable {
10171017
let authResponseCallback: IterableAuthResponseResult;
10181018
RNEventEmitter.addListener(IterableEventName.handleAuthCalled, () => {
10191019
// MOB-10423: Check if we can use chain operator (?.) here instead
1020-
1020+
// Asks frontend of the client/app to pass authToken
10211021
Iterable.savedConfig.authHandler!()
10221022
.then((promiseResult) => {
10231023
// Promise result can be either just String OR of type AuthResponse.
@@ -1038,6 +1038,8 @@ export class Iterable {
10381038
} else if (
10391039
authResponseCallback === IterableAuthResponseResult.FAILURE
10401040
) {
1041+
// We are currently only reporting JWT related errors. In
1042+
// the future, we should handle other types of errors as well.
10411043
if ((promiseResult as IterableAuthResponse).failureCallback) {
10421044
(promiseResult as IterableAuthResponse).failureCallback?.();
10431045
}
@@ -1067,8 +1069,14 @@ export class Iterable {
10671069
);
10681070
RNEventEmitter.addListener(
10691071
IterableEventName.handleAuthFailureCalled,
1070-
() => {
1072+
(authFailureResponse: IterableAuthFailure) => {
1073+
// Mark the flag for above listener to indicate something failed.
1074+
// `catch(err)` will only indicate failure on high level. No actions
1075+
// should be taken inside `catch(err)`.
10711076
authResponseCallback = IterableAuthResponseResult.FAILURE;
1077+
1078+
// Call the actual JWT error with `authFailure` object.
1079+
Iterable.savedConfig?.onJWTError?.(authFailureResponse);
10721080
}
10731081
);
10741082
}

src/core/classes/IterableConfig.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ export class IterableConfig {
209209
>;
210210

211211
/**
212-
* A callback function which is called when an error occurs while validating a JWT.
212+
* A callback function that is called when the SDK encounters an error while
213+
* validing the JWT.
213214
*
214215
* The retry for JWT should be automatically handled by the native SDK, so
215216
* this is just for logging/transparency purposes.
@@ -234,7 +235,8 @@ export class IterableConfig {
234235
logLevel: IterableLogLevel = IterableLogLevel.info;
235236

236237
/**
237-
* The retry policy to use when retrying a request.
238+
* Configuration for JWT refresh retry behavior.
239+
* If not specified, the SDK will use default retry behavior.
238240
*/
239241
retryPolicy?: IterableRetryPolicy;
240242

@@ -357,6 +359,13 @@ export class IterableConfig {
357359
*/
358360
// eslint-disable-next-line eqeqeq
359361
authHandlerPresent: this.authHandler != undefined,
362+
/**
363+
* A boolean indicating if an onJWTError handler is present.
364+
*
365+
* TODO: Figure out if this is purposeful
366+
*/
367+
// eslint-disable-next-line eqeqeq
368+
onJWTErrorPresent: this.onJWTError != undefined,
360369
/** The log level for the SDK. */
361370
logLevel: this.logLevel,
362371
expiringAuthTokenRefreshPeriod: this.expiringAuthTokenRefreshPeriod,
@@ -367,6 +376,7 @@ export class IterableConfig {
367376
dataRegion: this.dataRegion,
368377
pushPlatform: this.pushPlatform,
369378
encryptionEnforced: this.encryptionEnforced,
379+
retryPolicy: this.retryPolicy,
370380
};
371381
}
372382
}

0 commit comments

Comments
 (0)