Skip to content

Commit c679a26

Browse files
feat: Increase RESUME_SESSION_GRACE_MS to 5000ms and improve activity checks in webAuth start
1 parent 443d5ba commit c679a26

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

android/src/main/java/com/auth0/react/A0Auth0Module.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class A0Auth0Module(private val reactContext: ReactApplicationContext) : A0Auth0
4444

4545
// Grace window (ms) for an in-flight restored token exchange to complete before
4646
// resumeWebAuthSession resolves null.
47-
private const val RESUME_SESSION_GRACE_MS = 1500L
47+
private const val RESUME_SESSION_GRACE_MS = 5000L
4848

4949
private const val CREDENTIAL_MANAGER_ERROR_CODE = "CREDENTIAL_MANAGER_ERROR"
5050
private const val BIOMETRICS_AUTHENTICATION_ERROR_CODE = "BIOMETRICS_CONFIGURATION_ERROR"
@@ -174,10 +174,17 @@ class A0Auth0Module(private val reactContext: ReactApplicationContext) : A0Auth0
174174
}
175175

176176
builder.withParameters(cleanedParameters)
177+
178+
val activity = reactContext.currentActivity
179+
if (activity == null) {
180+
promise.reject("a0.activity_not_available", "Current Activity is not available")
181+
webAuthPromise = null
182+
return
183+
}
177184
// start() registers a LifecycleObserver internally (Auth0.Android 3.19.0+ for
178185
// process-death recovery), which must happen on the main thread.
179186
UiThreadUtil.runOnUiThread {
180-
builder.start(reactContext.currentActivity as Activity,
187+
builder.start(activity,
181188
object : com.auth0.android.callback.Callback<Credentials, AuthenticationException> {
182189
override fun onSuccess(result: Credentials) {
183190
val map = CredentialsParser.toMap(result)
@@ -460,10 +467,15 @@ class A0Auth0Module(private val reactContext: ReactApplicationContext) : A0Auth0
460467
)
461468
}
462469

470+
val activity = reactContext.currentActivity
471+
if (activity !is FragmentActivity) {
472+
promise.reject("a0.activity_not_available", "Current Activity is not a FragmentActivity")
473+
return
474+
}
463475
// start() registers a LifecycleObserver internally (Auth0.Android 3.19.0+),
464476
// which must happen on the main thread.
465477
UiThreadUtil.runOnUiThread {
466-
builder.start(reactContext.currentActivity as FragmentActivity,
478+
builder.start(activity,
467479
object : com.auth0.android.callback.Callback<Void?, AuthenticationException> {
468480
override fun onSuccess(result: Void?) {
469481
promise.resolve(true)

0 commit comments

Comments
 (0)