Skip to content

Commit 62b6a85

Browse files
committed
feat(SDK-559): expose Iterable.authManager.getAuthToken()
Bridge native JWT reads for parity with Android getAuthToken() and iOS IterableAPI.authToken, alongside existing getEmail/getUserId.
1 parent a8faf4a commit 62b6a85

13 files changed

Lines changed: 106 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Updates
44

5+
- Added `Iterable.authManager.getAuthToken()` to read the JWT currently held by the native SDK (SDK-559).
6+
- iOS: `IterableAPI.authToken`.
7+
- Android: `IterableApi.getAuthToken()`.
58
- Added `Iterable.disableDeviceForAllUsers()` to unregister this device's push token from every user associated with the device (SDK-550).
69
- iOS: forwards to native `IterableAPI.disableDeviceForAllUsers()`.
710
- Android: graceful no-op that logs a warning; use `disableDeviceForCurrentUser()` to disable push for the current user. There is no public native "all users" equivalent.

‎android/src/main/java/com/iterable/iterableapi/RNIterableInternal.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public static String getUserId() {
1616
return IterableApi.getInstance().getUserId();
1717
}
1818

19+
@Nullable
20+
public static String getAuthToken() {
21+
return IterableApi.getInstance().getAuthToken();
22+
}
23+
1924
public static JSONObject getInAppMessageJson(IterableInAppMessage message) {
2025
return message.toJSONObject();
2126
}

‎android/src/main/java/com/iterable/reactnative/RNIterableAPIModuleImpl.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ public void getUserId(Promise promise) {
249249
promise.resolve(RNIterableInternal.getUserId());
250250
}
251251

252+
public void getAuthToken(Promise promise) {
253+
promise.resolve(RNIterableInternal.getAuthToken());
254+
}
255+
252256
public void trackEvent(String name, @Nullable ReadableMap dataFields) {
253257
IterableLogger.v(TAG, "trackEvent");
254258
IterableApi.getInstance().track(name, optSerializedDataFields(dataFields));

‎android/src/newarch/java/com/RNIterableAPIModule.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public void getUserId(Promise promise) {
7272
moduleImpl.getUserId(promise);
7373
}
7474

75+
@Override
76+
public void getAuthToken(Promise promise) {
77+
moduleImpl.getAuthToken(promise);
78+
}
79+
7580
@Override
7681
public void trackEvent(String name, @Nullable ReadableMap dataFields) {
7782
moduleImpl.trackEvent(name, dataFields);

‎android/src/oldarch/java/com/RNIterableAPIModule.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public void getUserId(Promise promise) {
7373
moduleImpl.getUserId(promise);
7474
}
7575

76+
@ReactMethod
77+
public void getAuthToken(Promise promise) {
78+
moduleImpl.getAuthToken(promise);
79+
}
80+
7681
@ReactMethod
7782
public void trackEvent(String name, @Nullable ReadableMap dataFields) {
7883
moduleImpl.trackEvent(name, dataFields);

‎ios/RNIterableAPI/RNIterableAPI.mm‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ - (void)updateVisibleRows:(NSArray *)visibleRows {
283283
[_swiftAPI updateVisibleRows:visibleRows];
284284
}
285285

286+
- (void)getAuthToken:(RCTPromiseResolveBlock)resolve
287+
reject:(RCTPromiseRejectBlock)reject {
288+
[_swiftAPI getAuthToken:resolve rejecter:reject];
289+
}
290+
286291
- (void)passAlongAuthToken:(NSString *_Nullable)authToken {
287292
[_swiftAPI passAlongAuthToken:authToken];
288293
}
@@ -571,6 +576,11 @@ - (void)wakeApp {
571576
[_swiftAPI updateVisibleRows:visibleRows];
572577
}
573578

579+
RCT_EXPORT_METHOD(getAuthToken : (RCTPromiseResolveBlock)
580+
resolve rejecter : (RCTPromiseRejectBlock)reject) {
581+
[_swiftAPI getAuthToken:resolve rejecter:reject];
582+
}
583+
574584
RCT_EXPORT_METHOD(passAlongAuthToken : (NSString *_Nullable)authToken) {
575585
[_swiftAPI passAlongAuthToken:authToken];
576586
}

‎ios/RNIterableAPI/ReactIterableAPI.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ import React
500500

501501
// MARK: - SDK Auth Manager Functions
502502

503+
@objc(getAuthToken:rejecter:)
504+
public func getAuthToken(resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock) {
505+
ITBInfo()
506+
resolver(IterableAPI.authToken)
507+
}
508+
503509
@objc(passAlongAuthToken:)
504510
public func passAlongAuthToken(authToken: String?) {
505511
ITBInfo()

‎src/__mocks__/MockRNIterableAPI.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IterableInAppMessage } from '../inApp';
44
export class MockRNIterableAPI {
55
static email?: string;
66
static userId?: string;
7+
static authToken?: string | null;
78
static token?: string;
89
static lastPushPayload?: unknown;
910
static attributionInfo?: IterableAttributionInfo;
@@ -82,6 +83,12 @@ export class MockRNIterableAPI {
8283

8384
static setInAppShowResponse = jest.fn();
8485

86+
static async getAuthToken(): Promise<string | null> {
87+
return await new Promise((resolve) => {
88+
resolve(MockRNIterableAPI.authToken ?? null);
89+
});
90+
}
91+
8592
static passAlongAuthToken = jest.fn();
8693

8794
static pauseAuthRetries = jest.fn();

‎src/api/NativeRNIterableAPI.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export interface Spec extends TurboModule {
179179
): void;
180180

181181
// Auth
182+
getAuthToken(): Promise<string | null>;
182183
passAlongAuthToken(authToken?: string | null): void;
183184
pauseAuthRetries(pauseRetry: boolean): void;
184185

‎src/core/classes/Iterable.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,25 @@ describe('Iterable', () => {
10381038
});
10391039
});
10401040

1041+
describe('getAuthToken', () => {
1042+
it('should return the auth token from RNIterableAPI', async () => {
1043+
const expectedToken = 'jwt-token';
1044+
MockRNIterableAPI.authToken = expectedToken;
1045+
1046+
const result = await Iterable.authManager.getAuthToken();
1047+
1048+
expect(result).toBe(expectedToken);
1049+
});
1050+
1051+
it('should return null when RNIterableAPI has no auth token', async () => {
1052+
MockRNIterableAPI.authToken = null;
1053+
1054+
const result = await Iterable.authManager.getAuthToken();
1055+
1056+
expect(result).toBeNull();
1057+
});
1058+
});
1059+
10411060
describe('passAlongAuthToken', () => {
10421061
it('should call RNIterableAPI.passAlongAuthToken with a valid string token', async () => {
10431062
// GIVEN a valid auth token

0 commit comments

Comments
 (0)