Skip to content

Commit e85d660

Browse files
committed
refactor: remove onAuthFailure method and update event handler setup in Iterable class
1 parent 5810a0a commit e85d660

2 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/api/NativeRNIterableAPI.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,11 @@ export interface Spec extends TurboModule {
116116

117117
// Auth
118118
passAlongAuthToken(authToken?: string | null): void;
119-
onAuthFailure(authFailure: { userKey: string; failedAuthToken: string; failedRequestTime: number; failureReason: string }): void;
120119
pauseAuthRetries(pauseRetry: boolean): void;
121120

122121
// Wake app -- android only
123122
wakeApp(): void;
124123

125-
126124
// REQUIRED for RCTEventEmitter
127125
addListener(eventName: string): void;
128126
removeListeners(count: number): void;

src/core/classes/Iterable.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -933,27 +933,6 @@ export class Iterable {
933933
);
934934
}
935935

936-
/**
937-
* A callback function that is called when an authentication failure occurs.
938-
*
939-
* @param authFailure - The auth failure details
940-
*
941-
* @example
942-
* ```typescript
943-
* Iterable.onAuthFailure({
944-
* userKey: '1234567890',
945-
* failedAuthToken: '1234567890',
946-
* failedRequestTime: 1234567890,
947-
* failureReason: IterableAuthFailureReason.AUTH_TOKEN_EXPIRED,
948-
* });
949-
* ```
950-
*/
951-
static onAuthFailure(authFailure: IterableAuthFailure) {
952-
Iterable?.logger?.log('onAuthFailure');
953-
954-
RNIterableAPI.onAuthFailure(authFailure);
955-
}
956-
957936
/**
958937
* Pause the authentication retry mechanism.
959938
*
@@ -970,9 +949,35 @@ export class Iterable {
970949
RNIterableAPI.pauseAuthRetries(pauseRetry);
971950
}
972951

973-
/** * @internal
952+
/**
953+
* Sets up event handlers for various Iterable events.
954+
*
955+
* This method performs the following actions:
956+
* - Removes all existing listeners to avoid duplicate listeners.
957+
* - Adds listeners for URL handling, custom actions, in-app messages, and authentication.
958+
*
959+
* Event Handlers:
960+
* - `handleUrlCalled`: Invokes the URL handler if configured, with a delay on Android to allow the activity to wake up.
961+
* - `handleCustomActionCalled`: Invokes the custom action handler if configured.
962+
* - `handleInAppCalled`: Invokes the in-app handler if configured and sets the in-app show response.
963+
* - `handleAuthCalled`: Invokes the authentication handler if configured and handles the promise result.
964+
* - `handleAuthSuccessCalled`: Sets the authentication response callback to success.
965+
* - `handleAuthFailureCalled`: Sets the authentication response callback to failure.
966+
*
967+
* Helper Functions:
968+
* - `callUrlHandler`: Calls the URL handler and attempts to open the URL if the handler returns false.
969+
*
970+
* @internal
974971
*/
975972
private static setupEventHandlers() {
973+
// Remove all listeners to avoid duplicate listeners
974+
RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled);
975+
RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled);
976+
RNEventEmitter.removeAllListeners(
977+
IterableEventName.handleCustomActionCalled
978+
);
979+
RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled);
980+
976981
if (Iterable.savedConfig.urlHandler) {
977982
RNEventEmitter.addListener(IterableEventName.handleUrlCalled, (dict) => {
978983
const url = dict.url;

0 commit comments

Comments
 (0)