Skip to content

Commit 536a68e

Browse files
committed
fixes
1 parent 765592c commit 536a68e

File tree

5 files changed

+29
-34
lines changed

5 files changed

+29
-34
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ dependencies {
9595

9696
implementation(Config.Libs.Misc.permissions)
9797
implementation(Config.Libs.Androidx.constraint)
98-
debugImplementation(Config.Libs.Misc.leakCanary)
9998

10099
val composeBom = platform("androidx.compose:compose-bom:2025.02.00")
101100
implementation(composeBom)

app/src/main/java/com/firebase/uidemo/auth/compose/SignedInScreen.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ fun SignedInScreen(
9595
}
9696
}
9797

98-
/* ---------------- profile details ---------------- */
9998

10099
@OptIn(ExperimentalGlideComposeApi::class)
101100
@Composable

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

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.firebase.ui.auth.compose
22

3-
import android.content.Intent
3+
import android.app.Activity
44
import androidx.activity.compose.rememberLauncherForActivityResult
55
import androidx.compose.foundation.layout.Box
66
import androidx.compose.foundation.layout.fillMaxSize
77
import androidx.compose.material3.CircularProgressIndicator
88
import androidx.compose.runtime.*
9+
import androidx.compose.runtime.saveable.rememberSaveable
910
import androidx.compose.ui.Alignment
1011
import androidx.compose.ui.Modifier
1112
import com.firebase.ui.auth.AuthUI
1213
import com.firebase.ui.auth.AuthUI.IdpConfig
1314
import com.firebase.ui.auth.FirebaseAuthUIActivityResultContract
1415
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult
1516
import com.google.firebase.auth.FirebaseAuth
16-
import kotlinx.coroutines.launch
1717

1818
/**
1919
* Composable that handles Firebase Auth UI sign-in and automatically swaps to [signedInContent]
@@ -39,36 +39,23 @@ fun FirebaseAuthUI(
3939
tosUrl: String? = null,
4040
privacyPolicyUrl: String? = null,
4141
enableCredentials: Boolean = true,
42-
enableAnonymousUpgrade: Boolean = false
42+
enableAnonymousUpgrade: Boolean = false,
4343
) {
4444
val auth = remember { FirebaseAuth.getInstance() }
4545
val authUI = remember { AuthUI.getInstance() }
46-
val scope = rememberCoroutineScope()
4746

48-
/* ------------- 1) Observe auth state ------------- */
4947
val firebaseUser by
5048
produceState(initialValue = auth.currentUser, auth) {
51-
val listener =
52-
FirebaseAuth.AuthStateListener { firebaseAuth ->
53-
value = firebaseAuth.currentUser
54-
}
49+
val listener = FirebaseAuth.AuthStateListener { value = it.currentUser }
5550
auth.addAuthStateListener(listener)
5651
awaitDispose { auth.removeAuthStateListener(listener) }
5752
}
5853

59-
/* ------------- 2) If signed in, show caller-provided screen ------------- */
6054
if (firebaseUser != null) {
6155
signedInContent()
6256
return
6357
}
6458

65-
/* ------------- 3) Otherwise prepare & launch Firebase UI sign-in ------------- */
66-
val signInLauncher =
67-
rememberLauncherForActivityResult(
68-
contract = FirebaseAuthUIActivityResultContract(),
69-
onResult = onSignInResult
70-
)
71-
7259
val signInIntent =
7360
remember(
7461
providers,
@@ -93,21 +80,23 @@ fun FirebaseAuthUI(
9380
}
9481
}
9582
.build()
96-
.apply {
97-
addFlags(
98-
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
99-
)
100-
}
10183
}
10284

103-
/* ­------------- 4) Launch once per composable lifetime ------------- */
104-
LaunchedEffect(signInIntent) {
105-
// Launch from a coroutine so we’re safe even inside composition
106-
scope.launch { signInLauncher.launch(signInIntent) }
107-
}
85+
var signInAttempted by rememberSaveable { mutableStateOf(false) }
10886

109-
/* Optional: lightweight in-place progress indicator while Firebase UI Activity starts */
110-
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
111-
CircularProgressIndicator()
87+
val launcher =
88+
rememberLauncherForActivityResult(FirebaseAuthUIActivityResultContract()) { result ->
89+
onSignInResult(result)
90+
91+
signInAttempted = result.resultCode != Activity.RESULT_OK
92+
}
93+
94+
LaunchedEffect(Unit) {
95+
if (!signInAttempted) {
96+
signInAttempted = true
97+
launcher.launch(signInIntent)
98+
}
11299
}
100+
101+
Box(Modifier.fillMaxSize(), Alignment.Center) { CircularProgressIndicator() }
113102
}

auth/src/main/java/com/firebase/ui/auth/ui/email/EmailActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ class EmailActivity : AppCompatBase(), RegisterEmailFragment.AnonymousUpgradeLis
162162
IdpResponse.Builder(newUser).build(),
163163
password
164164
)
165-
finish()
165+
val result = IdpResponse.Builder(newUser).build().toIntent()
166+
setResult(RESULT_OK, result)
166167
},
167168
onRegisterError = { e ->
168169
}
@@ -284,7 +285,8 @@ class EmailActivity : AppCompatBase(), RegisterEmailFragment.AnonymousUpgradeLis
284285
IdpResponse.Builder(newUser).build(),
285286
password
286287
)
287-
finish()
288+
val result = IdpResponse.Builder(newUser).build().toIntent()
289+
setResult(RESULT_OK, result)
288290
},
289291
onRegisterError = { e ->
290292

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ class AuthMethodPickerActivity : AppCompatBase() {
273273
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
274274
super.onActivityResult(requestCode, resultCode, data)
275275
hideProgress()
276+
277+
// forward the outcome upstream and close
278+
if (resultCode != RESULT_CANCELED) {
279+
setResult(resultCode, data)
280+
finish()
281+
}
276282
}
277283

278284
private fun handleCredentialManagerResult(cred: Credential) {

0 commit comments

Comments
 (0)