Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/preserve-google-sign-in-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/expo-google-signin': patch
---

Fix Android Google Sign-In provider failures being reported as user cancellation.
1 change: 1 addition & 0 deletions packages/expo-google-signin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ dependencies {
implementation "androidx.credentials:credentials-play-services-auth:1.3.0"
implementation "com.google.android.libraries.identity.googleid:googleid:1.1.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
testImplementation "junit:junit:4.13.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ClerkGoogleSignInModule : Module() {

handleSignInResult(result, promise)
} catch (e: GetCredentialCancellationException) {
promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
rejectCredentialCancellation(promise, e)
} catch (e: NoCredentialException) {
promise.reject("NO_SAVED_CREDENTIAL_FOUND", "No saved credential found", e)
} catch (e: GetCredentialException) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class ClerkGoogleSignInModule : Module() {

handleSignInResult(result, promise)
} catch (e: GetCredentialCancellationException) {
promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
rejectCredentialCancellation(promise, e)
} catch (e: NoCredentialException) {
promise.reject("NO_SAVED_CREDENTIAL_FOUND", "No saved credential found", e)
} catch (e: GetCredentialException) {
Expand Down Expand Up @@ -191,7 +191,7 @@ class ClerkGoogleSignInModule : Module() {

handleSignInResult(result, promise)
} catch (e: GetCredentialCancellationException) {
promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
rejectCredentialCancellation(promise, e)
} catch (e: GetCredentialException) {
promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
} catch (e: Exception) {
Expand All @@ -215,6 +215,17 @@ class ClerkGoogleSignInModule : Module() {

// MARK: - Helpers

private fun rejectCredentialCancellation(promise: Promise, exception: GetCredentialCancellationException) {
val message = exception.message ?: "Google Sign-In failed"

if (isExplicitUserCancellation(message)) {
promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", exception)
return
}

promise.reject("GOOGLE_SIGN_IN_ERROR", message, exception)
}

private fun handleSignInResult(result: GetCredentialResponse, promise: Promise) {
when (val credential = result.credential) {
is CustomCredential -> {
Expand Down Expand Up @@ -255,3 +266,9 @@ class ClerkGoogleSignInModule : Module() {
}
}
}

private val explicitUserCancellationPattern =
Regex("^(?:\\[\\d+]\\s*)?cancel(?:l)?ed by user\\.?$", RegexOption.IGNORE_CASE)

internal fun isExplicitUserCancellation(message: String): Boolean =
explicitUserCancellationPattern.matches(message.trim())
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package expo.modules.clerk.googlesignin

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class ClerkGoogleSignInModuleTest {
@Test
fun identifiesExplicitUserCancellation() {
assertTrue(isExplicitUserCancellation("[16] Cancelled by user."))
assertTrue(isExplicitUserCancellation("Canceled by user"))
assertTrue(isExplicitUserCancellation(" cancelled by user "))
}

@Test
fun preservesProviderFailures() {
assertFalse(isExplicitUserCancellation("[16] Account reauth failed."))
assertFalse(isExplicitUserCancellation("Developer console is not set up correctly."))
assertFalse(isExplicitUserCancellation("Request was not cancelled by user"))
}
}