diff --git a/android/build.gradle b/android/build.gradle index 3c7b8ed..56c3229 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -129,7 +129,7 @@ dependencies { implementation "androidx.browser:browser:1.2.0" - implementation("com.authsignal:authsignal-android:1.0.4") + implementation("com.authsignal:authsignal-android:1.0.5") } if (isNewArchitectureEnabled()) { diff --git a/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java b/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java index 99e20c5..39351db 100644 --- a/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java +++ b/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import com.authsignal.push.AuthsignalPush; +import com.authsignal.push.models.PushChallenge; import com.authsignal.push.models.PushCredential; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Promise; @@ -56,11 +57,11 @@ public void getCredential(Promise promise) { .getCredentialAsync() .thenAcceptAsync((response) -> { if (response.getError() != null) { - promise.reject("getCredential error", response.getError()); + promise.reject("getCredentialError", response.getError()); } else { PushCredential credential = response.getData(); WritableMap map = Arguments.createMap(); - map.putString("credentialID", credential.getCredentialID()); + map.putString("credentialId", credential.getCredentialId()); map.putString("createdAt", credential.getCreatedAt()); map.putString("lastAuthenticatedAt", credential.getLastAuthenticatedAt()); promise.resolve(map); @@ -82,7 +83,7 @@ public void addCredential(String token, Promise promise) { if (response.getErrorType() != null && response.getErrorType().equals("TYPE_TOKEN_NOT_SET")) { promise.reject("tokenNotSetError", "TOKEN_NOT_SET"); } else if (response.getError() != null) { - promise.reject("addCredential error", response.getError()); + promise.reject("addCredentialError", response.getError()); } else { promise.resolve(response.getData()); } @@ -101,7 +102,7 @@ public void removeCredential(Promise promise) { .removeCredentialAsync() .thenAcceptAsync(response -> { if (response.getError() != null) { - promise.reject("removeCredential error", response.getError()); + promise.reject("removeCredentialError", response.getError()); } else { promise.resolve(response.getData()); } @@ -120,9 +121,22 @@ public void getChallenge(Promise promise) { .getChallengeAsync() .thenAcceptAsync(response -> { if (response.getError() != null) { - promise.reject("getChallenge error", response.getError()); + promise.reject("getChallengeError", response.getError()); } else { - promise.resolve(response.getData()); + PushChallenge challenge = response.getData(); + + if (challenge == null) { + promise.resolve(null); + } else { + WritableMap map = Arguments.createMap(); + map.putString("challengeId", challenge.getChallengeId()); + map.putString("actionCode", challenge.getActionCode()); + map.putString("idempotencyKey", challenge.getIdempotencyKey()); + map.putString("ipAddress", challenge.getIpAddress()); + map.putString("deviceId", challenge.getDeviceId()); + map.putString("userAgent", challenge.getUserAgent()); + promise.resolve(map); + } } }); } else { @@ -144,7 +158,7 @@ public void updateChallenge( .updateChallengeAsync(challengeId, approved, verificationCode) .thenAcceptAsync(response -> { if (response.getError() != null) { - promise.reject("updateChallenge error", response.getError()); + promise.reject("updateChallengeError", response.getError()); } else { promise.resolve(response.getData()); } diff --git a/ios/AuthsignalPushModule.swift b/ios/AuthsignalPushModule.swift index 84b9254..f4484cb 100644 --- a/ios/AuthsignalPushModule.swift +++ b/ios/AuthsignalPushModule.swift @@ -37,9 +37,9 @@ class AuthsignalPushModule: NSObject { reject("getCredential error", error, nil) } else if let data = response.data { let credential: [String: String?] = [ - "credentialId": response.data!.credentialId, - "createdAt": response.data!.createdAt, - "lastAuthenticatedAt": response.data!.lastAuthenticatedAt, + "credentialId": data.credentialId, + "createdAt": data.createdAt, + "lastAuthenticatedAt": data.lastAuthenticatedAt, ] resolve(credential) @@ -67,7 +67,7 @@ class AuthsignalPushModule: NSObject { if (response.errorCode == "TOKEN_NOT_SET") { reject("tokenNotSetError", "TOKEN_NOT_SET", nil) } else if let error = response.error { - reject("addCredential error", error, nil) + reject("addCredentialError", error, nil) } else { resolve(response.data) } @@ -87,7 +87,7 @@ class AuthsignalPushModule: NSObject { let response = await authsignal.removeCredential() if let error = response.error { - reject("removeCredential error", error, nil) + reject("removeCredentialError", error, nil) } else { resolve(response.data) } @@ -107,9 +107,20 @@ class AuthsignalPushModule: NSObject { let response = await authsignal.getChallenge() if let error = response.error { - reject("getChallenge error", error, nil) + reject("getChallengeError", error, nil) + } else if let data = response.data as? PushChallenge { + let challenge: [String: String?] = [ + "challengeId": data.challengeId, + "actionCode": data.actionCode, + "idempotencyKey": data.idempotencyKey, + "userAgent": data.userAgent, + "deviceId": data.deviceId, + "ipAddress": data.ipAddress, + ] + + resolve(challenge) } else { - resolve(response.data) + resolve(nil) } } } @@ -138,7 +149,7 @@ class AuthsignalPushModule: NSObject { ) if let error = response.error { - reject("updateChallenge error", error, nil) + reject("updateChallengeError", error, nil) } else { resolve(response.data) } diff --git a/package.json b/package.json index a837bf5..1dfa039 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-authsignal", - "version": "1.0.1", + "version": "1.0.2", "description": "The official Authsignal React Native library.", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/react-native-authsignal.podspec b/react-native-authsignal.podspec index 875b530..f9c7bf7 100644 --- a/react-native-authsignal.podspec +++ b/react-native-authsignal.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm,swift}" s.dependency "React-Core" - s.dependency 'Authsignal', '1.0.3' + s.dependency 'Authsignal', '1.0.4' # Don't install the dependencies when we run `pod install` in the old architecture. if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then diff --git a/src/push.ts b/src/push.ts index 32bc40c..749a847 100644 --- a/src/push.ts +++ b/src/push.ts @@ -1,6 +1,10 @@ import { NativeModules } from 'react-native'; import { LINKING_ERROR } from './error'; -import type { AuthsignalResponse } from './types'; +import type { + AuthsignalResponse, + PushChallenge, + PushCredential, +} from './types'; interface ConstructorArgs { tenantID: string; @@ -8,12 +12,6 @@ interface ConstructorArgs { enableLogging: boolean; } -interface PushCredential { - credentialId: string; - createdAt: string; - lastAuthenticatedAt?: string; -} - let initialized = false; const AuthsignalPushModule = NativeModules.AuthsignalPushModule @@ -97,7 +95,7 @@ export class AuthsignalPush { } } - async getChallenge(): Promise> { + async getChallenge(): Promise> { await this.ensureModuleIsInitialized(); try { diff --git a/src/types.ts b/src/types.ts index de2df4b..8859a13 100644 --- a/src/types.ts +++ b/src/types.ts @@ -44,3 +44,18 @@ export interface VerifyResponse { token?: string; failureReason?: string; } + +export interface PushCredential { + credentialId: string; + createdAt: string; + lastAuthenticatedAt?: string; +} + +export interface PushChallenge { + challengeId: string; + actionCode?: string; + idempotencyKey?: string; + userAgent?: string; + deviceId?: string; + ipAddress?: string; +}