Skip to content

Commit d9ab89a

Browse files
migrate to new architecture (#80)
* migrate to new architecture * wip * wip * wip * wip
1 parent 1ae5b14 commit d9ab89a

File tree

102 files changed

+3572
-5131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3572
-5131
lines changed

android/build.gradle

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
buildscript {
2-
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Authsignal_kotlinVersion"]
3-
4-
repositories {
5-
google()
6-
mavenCentral()
7-
}
8-
9-
dependencies {
10-
classpath 'com.android.tools.build:gradle:8.1.4'
11-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12-
}
13-
}
14-
151
apply plugin: 'com.android.library'
162
apply plugin: 'org.jetbrains.kotlin.android'
3+
apply plugin: 'com.facebook.react'
174

185
def getExtOrDefault(name) {
196
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Authsignal_' + name]
@@ -45,7 +32,7 @@ android {
4532
}
4633
}
4734

48-
lintOptions {
35+
lint {
4936
disable 'GradleCompatible'
5037
}
5138

@@ -68,12 +55,9 @@ repositories {
6855
google()
6956
}
7057

71-
def kotlin_version = getExtOrDefault("kotlinVersion")
72-
7358
dependencies {
7459
//noinspection GradleDynamicVersion
7560
implementation "com.facebook.react:react-native:+"
76-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
7761

7862
implementation "androidx.browser:browser:1.2.0"
7963

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Authsignal_kotlinVersion=1.9.24
1+
Authsignal_kotlinVersion=2.1.0
22
Authsignal_minSdkVersion=24
33
Authsignal_targetSdkVersion=34
44
Authsignal_compileSdkVersion=34

android/src/main/java/com/authsignal/react/AuthsignalEmailModule.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,24 @@ import com.authsignal.email.AuthsignalEmail
55
import com.facebook.react.bridge.Arguments
66
import com.facebook.react.bridge.Promise
77
import com.facebook.react.bridge.ReactApplicationContext
8-
import com.facebook.react.bridge.ReactContextBaseJavaModule
98
import com.facebook.react.bridge.ReactMethod
9+
import com.facebook.react.module.annotations.ReactModule
1010
import kotlinx.coroutines.CoroutineScope
1111
import kotlinx.coroutines.Dispatchers
1212
import kotlinx.coroutines.SupervisorJob
1313
import kotlinx.coroutines.launch
1414

15+
@ReactModule(name = AuthsignalEmailModule.NAME)
1516
class AuthsignalEmailModule(private val reactContext: ReactApplicationContext) :
16-
ReactContextBaseJavaModule(
17-
reactContext
18-
) {
17+
NativeAuthsignalEmailModuleSpec(reactContext) {
1918
private var authsignal: AuthsignalEmail? = null
2019

2120
private val defaultError = "unexpected_error"
2221

2322
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
2423

25-
override fun getConstants(): Map<String, Any>? {
26-
val constants: MutableMap<String, Any> = HashMap()
27-
constants["bundleIdentifier"] = reactContext.applicationInfo.packageName
28-
return constants
29-
}
30-
31-
override fun getName(): String {
32-
return "AuthsignalEmailModule"
33-
}
34-
3524
@ReactMethod
36-
fun initialize(tenantID: String, baseURL: String, promise: Promise) {
25+
override fun initialize(tenantID: String, baseURL: String, promise: Promise) {
3726
val currentActivity = reactContext.currentActivity
3827

3928
if (currentActivity != null) {
@@ -44,7 +33,7 @@ class AuthsignalEmailModule(private val reactContext: ReactApplicationContext) :
4433
}
4534

4635
@ReactMethod
47-
fun enroll(email: String, promise: Promise) {
36+
override fun enroll(email: String, promise: Promise) {
4837
launch(promise) {
4938
val response = it.enroll(email)
5039

@@ -62,7 +51,7 @@ class AuthsignalEmailModule(private val reactContext: ReactApplicationContext) :
6251
}
6352

6453
@ReactMethod
65-
fun challenge(promise: Promise) {
54+
override fun challenge(promise: Promise) {
6655
launch(promise) {
6756
val response = it.challenge()
6857

@@ -80,7 +69,7 @@ class AuthsignalEmailModule(private val reactContext: ReactApplicationContext) :
8069
}
8170

8271
@ReactMethod
83-
fun verify(code: String, promise: Promise) {
72+
override fun verify(code: String, promise: Promise) {
8473
launch(promise) {
8574
val response = it.verify(code)
8675

@@ -110,4 +99,8 @@ class AuthsignalEmailModule(private val reactContext: ReactApplicationContext) :
11099
}
111100
}
112101
}
102+
103+
companion object {
104+
const val NAME = "AuthsignalEmailModule"
105+
}
113106
}

android/src/main/java/com/authsignal/react/AuthsignalInAppModule.kt

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,30 @@ import com.authsignal.models.api.AppAttestationProvider
77
import com.facebook.react.bridge.Arguments
88
import com.facebook.react.bridge.Promise
99
import com.facebook.react.bridge.ReactApplicationContext
10-
import com.facebook.react.bridge.ReactContextBaseJavaModule
1110
import com.facebook.react.bridge.ReactMethod
1211
import com.facebook.react.bridge.ReadableMap
12+
import com.facebook.react.module.annotations.ReactModule
1313
import kotlinx.coroutines.CoroutineScope
1414
import kotlinx.coroutines.Dispatchers
1515
import kotlinx.coroutines.SupervisorJob
1616
import kotlinx.coroutines.launch
1717

18+
@ReactModule(name = AuthsignalInAppModule.NAME)
1819
class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
19-
ReactContextBaseJavaModule(
20-
reactContext
21-
) {
20+
NativeAuthsignalInAppModuleSpec(reactContext) {
2221
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
2322
private var authsignal: AuthsignalInApp? = null
2423
private var defaultError = "unexpected_error"
2524

26-
override fun getConstants(): Map<String, Any>? {
27-
val constants: MutableMap<String, Any> = HashMap()
28-
constants["bundleIdentifier"] = reactContext.applicationInfo.packageName
29-
return constants
30-
}
31-
32-
override fun getName(): String {
33-
return "AuthsignalInAppModule"
34-
}
35-
3625
@ReactMethod
37-
fun initialize(tenantID: String?, baseURL: String?, promise: Promise) {
38-
Log.d("AuthsignalInAppModule", "initialize: $tenantID, $baseURL")
39-
authsignal = AuthsignalInApp(tenantID!!, baseURL!!, context = reactContext)
26+
override fun initialize(tenantID: String, baseURL: String, promise: Promise) {
27+
authsignal = AuthsignalInApp(tenantID, baseURL, context = reactContext)
4028

4129
promise.resolve(null)
4230
}
4331

4432
@ReactMethod
45-
fun getCredential(username: String?, promise: Promise) {
33+
override fun getCredential(username: String?, promise: Promise) {
4634
launch(promise) {
4735
val response = it.getCredential(username = username)
4836

@@ -65,8 +53,10 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
6553
}
6654

6755
@ReactMethod
68-
fun addCredential(
56+
override fun addCredential(
6957
token: String?,
58+
_requireUserAuthentication: Boolean,
59+
_keychainAccess: String?,
7060
username: String?,
7161
appAttestationMap: ReadableMap?,
7262
promise: Promise
@@ -109,7 +99,7 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
10999
}
110100

111101
@ReactMethod
112-
fun removeCredential(username: String?, promise: Promise) {
102+
override fun removeCredential(username: String?, promise: Promise) {
113103
launch(promise) {
114104
val response = it.removeCredential(username = username)
115105

@@ -124,7 +114,7 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
124114
}
125115

126116
@ReactMethod
127-
fun verify(
117+
override fun verify(
128118
action: String?,
129119
username: String?,
130120
promise: Promise
@@ -137,19 +127,23 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
137127

138128
promise.reject(errorCode, response.error)
139129
} else {
140-
val data = response.data!!
141-
val map = Arguments.createMap()
142-
map.putString("token", data.token)
143-
map.putString("userId", data.userId)
144-
map.putString("userAuthenticatorId", data.userAuthenticatorId)
145-
map.putString("username", data.username)
146-
promise.resolve(map)
130+
val data = response.data
131+
if (data != null) {
132+
val map = Arguments.createMap()
133+
map.putString("token", data.token)
134+
map.putString("userId", data.userId)
135+
map.putString("userAuthenticatorId", data.userAuthenticatorId)
136+
map.putString("username", data.username)
137+
promise.resolve(map)
138+
} else {
139+
promise.reject(defaultError, "No data returned")
140+
}
147141
}
148142
}
149143
}
150144

151145
@ReactMethod
152-
fun createPin(pin: String, username: String, token: String?, promise: Promise) {
146+
override fun createPin(pin: String, username: String, token: String?, promise: Promise) {
153147
launch(promise) {
154148
val response = it.createPin(
155149
pin = pin,
@@ -162,19 +156,23 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
162156

163157
promise.reject(errorCode, response.error)
164158
} else {
165-
val data = response.data!!
166-
val map = Arguments.createMap()
167-
map.putString("credentialId", data.credentialId)
168-
map.putString("createdAt", data.createdAt)
169-
map.putString("userId", data.userId)
170-
map.putString("lastAuthenticatedAt", data.lastAuthenticatedAt)
171-
promise.resolve(map)
159+
val data = response.data
160+
if (data != null) {
161+
val map = Arguments.createMap()
162+
map.putString("credentialId", data.credentialId)
163+
map.putString("createdAt", data.createdAt)
164+
map.putString("userId", data.userId)
165+
map.putString("lastAuthenticatedAt", data.lastAuthenticatedAt)
166+
promise.resolve(map)
167+
} else {
168+
promise.reject(defaultError, "No data returned")
169+
}
172170
}
173171
}
174172
}
175173

176174
@ReactMethod
177-
fun verifyPin(pin: String, username: String, action: String?, promise: Promise) {
175+
override fun verifyPin(pin: String, username: String, action: String?, promise: Promise) {
178176
launch(promise) {
179177
val response = it.verifyPin(
180178
pin = pin,
@@ -187,18 +185,22 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
187185

188186
promise.reject(errorCode, response.error)
189187
} else {
190-
val data = response.data!!
191-
val map = Arguments.createMap()
192-
map.putBoolean("isVerified", data.isVerified)
193-
map.putString("token", data.token)
194-
map.putString("userId", data.userId)
195-
promise.resolve(map)
188+
val data = response.data
189+
if (data != null) {
190+
val map = Arguments.createMap()
191+
map.putBoolean("isVerified", data.isVerified)
192+
map.putString("token", data.token)
193+
map.putString("userId", data.userId)
194+
promise.resolve(map)
195+
} else {
196+
promise.reject(defaultError, "No data returned")
197+
}
196198
}
197199
}
198200
}
199201

200202
@ReactMethod
201-
fun deletePin(username: String, promise: Promise) {
203+
override fun deletePin(username: String, promise: Promise) {
202204
launch(promise) {
203205
val response = it.deletePin(username = username)
204206

@@ -213,7 +215,7 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
213215
}
214216

215217
@ReactMethod
216-
fun getAllPinUsernames(promise: Promise) {
218+
override fun getAllPinUsernames(promise: Promise) {
217219
launch(promise) {
218220
val response = it.getAllPinUsernames()
219221

@@ -240,4 +242,8 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
240242
}
241243
}
242244
}
245+
246+
companion object {
247+
const val NAME = "AuthsignalInAppModule"
248+
}
243249
}

0 commit comments

Comments
 (0)