Skip to content

Commit b0c15b1

Browse files
committed
fix: linking credential hangs AuthState
1 parent 192b6f9 commit b0c15b1

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

auth/src/main/java/com/firebase/ui/auth/compose/FirebaseAuthUI.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
2929
import kotlinx.coroutines.flow.callbackFlow
3030
import kotlinx.coroutines.flow.combine
3131
import kotlinx.coroutines.flow.distinctUntilChanged
32-
import kotlinx.coroutines.flow.drop
33-
import kotlinx.coroutines.flow.merge
34-
import kotlinx.coroutines.flow.onStart
3532
import kotlinx.coroutines.tasks.await
3633
import java.util.concurrent.ConcurrentHashMap
3734

@@ -221,7 +218,7 @@ class FirebaseAuthUI private constructor(
221218
) { firebaseState, internalState ->
222219
// Prefer non-idle internal states (like PasswordResetLinkSent, Error, etc.)
223220
if (internalState !is AuthState.Idle) internalState else firebaseState
224-
}
221+
}.distinctUntilChanged()
225222
}
226223

227224
/**

auth/src/main/java/com/firebase/ui/auth/compose/configuration/auth_provider/EmailAuthProvider+FirebaseAuthUI.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,25 @@ internal suspend fun FirebaseAuthUI.signInWithEmailAndPassword(
338338
} else {
339339
// Normal sign-in
340340
auth.signInWithEmailAndPassword(email, password).await()
341-
.also { result ->
341+
.let { result ->
342342
// If there's a credential to link, link it after sign-in
343343
if (credentialForLinking != null) {
344-
return result.user?.linkWithCredential(credentialForLinking)?.await()
345-
.also { linkResult ->
346-
// Merge profile from social provider
347-
linkResult?.user?.let { user ->
348-
mergeProfile(
349-
auth,
350-
user.displayName,
351-
user.photoUrl
352-
)
353-
}
354-
}
344+
val linkResult = result.user
345+
?.linkWithCredential(credentialForLinking)
346+
?.await()
347+
348+
// Merge profile from social provider
349+
linkResult?.user?.let { user ->
350+
mergeProfile(
351+
auth,
352+
user.displayName,
353+
user.photoUrl
354+
)
355+
}
356+
357+
linkResult ?: result
358+
} else {
359+
result
355360
}
356361
}
357362
}.also {
@@ -773,7 +778,7 @@ suspend fun FirebaseAuthUI.signInWithEmailLink(
773778
.getInstance(appExplicitlyForValidation)
774779

775780
// Safe link: Validate that both credentials can be linked
776-
val result = authExplicitlyForValidation
781+
authExplicitlyForValidation
777782
.signInWithCredential(emailLinkCredential).await()
778783
.user?.linkWithCredential(storedCredentialForLink)?.await()
779784
.also { result ->
@@ -788,10 +793,9 @@ suspend fun FirebaseAuthUI.signInWithEmailLink(
788793
updateAuthState(AuthState.Error(accountLinkingException))
789794
throw accountLinkingException
790795
}
791-
return result
792796
} else {
793797
// Non-upgrade: Sign in with email link, then link social credential
794-
val result = auth.signInWithCredential(emailLinkCredential).await()
798+
auth.signInWithCredential(emailLinkCredential).await()
795799
// Link the social credential
796800
.user?.linkWithCredential(storedCredentialForLink)?.await()
797801
.also { result ->
@@ -804,7 +808,6 @@ suspend fun FirebaseAuthUI.signInWithEmailLink(
804808
)
805809
}
806810
}
807-
return result
808811
}
809812
}
810813
// Clear DataStore after success

composeapp/src/main/java/com/firebase/composeapp/MainActivity.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MainActivity : ComponentActivity() {
6666
AuthProvider.Email(
6767
isDisplayNameRequired = true,
6868
isEmailLinkForceSameDeviceEnabled = true,
69-
isEmailLinkSignInEnabled = true,
69+
isEmailLinkSignInEnabled = false,
7070
emailLinkActionCodeSettings = actionCodeSettings {
7171
// The continue URL - where to redirect after email link is clicked
7272
url = "https://temp-test-aa342.firebaseapp.com"
@@ -159,10 +159,6 @@ class MainActivity : ComponentActivity() {
159159
is Route.MfaEnrollment -> NavEntry(entry) {
160160
LaunchMfaEnrollment(authUI, backStack)
161161
}
162-
163-
is Route.MfaEnrollment -> NavEntry(entry) {
164-
LaunchMfaEnrollment(authUI, backStack)
165-
}
166162
}
167163
}
168164
)

0 commit comments

Comments
 (0)