Skip to content

Commit 657aa3f

Browse files
committed
fix: issues for the Sign In Screen
1 parent a594050 commit 657aa3f

File tree

7 files changed

+77
-7
lines changed

7 files changed

+77
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ class FirebaseAuthUI private constructor(
316316

317317
/**
318318
* Updates the internal authentication state.
319-
* This method is intended for internal use by authentication operations.
319+
* This method can be used to manually trigger state updates when the Firebase Auth state
320+
* listener doesn't automatically detect changes (e.g., after reloading user properties).
320321
*
321322
* @param state The new [AuthState] to emit
322-
* @suppress This is an internal API
323323
*/
324-
internal fun updateAuthState(state: AuthState) {
324+
fun updateAuthState(state: AuthState) {
325325
_authStateFlow.value = state
326326
}
327327

auth/src/main/java/com/firebase/ui/auth/compose/configuration/auth_provider/AuthProvider.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ abstract class AuthProvider(open val providerId: String, open val providerName:
154154
* A list of custom password validation rules.
155155
*/
156156
val passwordValidationRules: List<PasswordRule>,
157+
158+
/**
159+
* Optional custom button label to differentiate between multiple email providers.
160+
* If null, uses the default string from stringProvider. Defaults to null.
161+
*/
162+
val buttonLabel: String? = null,
157163
) : AuthProvider(providerId = Provider.EMAIL.id, providerName = Provider.EMAIL.providerName) {
158164
companion object {
159165
const val SESSION_ID_LENGTH = 10

auth/src/main/java/com/firebase/ui/auth/compose/ui/components/AuthProviderButton.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ internal fun resolveProviderLabel(
153153
context: android.content.Context
154154
): String = when (provider) {
155155
is AuthProvider.GenericOAuth -> provider.buttonLabel
156+
is AuthProvider.Email -> {
157+
// Use custom button label if provided, otherwise use default
158+
provider.buttonLabel ?: stringProvider.signInWithEmail
159+
}
156160
is AuthProvider.Apple -> {
157161
// Use Apple-specific locale if provided, otherwise use default stringProvider
158162
if (provider.locale != null) {

auth/src/main/java/com/firebase/ui/auth/compose/ui/screens/FirebaseAuthScreen.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,32 @@ fun FirebaseAuthScreen(
322322
onReloadUser = {
323323
coroutineScope.launch {
324324
try {
325+
// Reload user to get fresh data from server
325326
authUI.getCurrentUser()?.reload()
326327
authUI.getCurrentUser()?.getIdToken(true)
328+
329+
// Check the user's email verification status after reload
330+
val user = authUI.getCurrentUser()
331+
if (user != null) {
332+
// If email is now verified, transition to Success state
333+
if (user.isEmailVerified) {
334+
authUI.updateAuthState(
335+
AuthState.Success(
336+
result = null,
337+
user = user,
338+
isNewUser = false
339+
)
340+
)
341+
} else {
342+
// Email still not verified, keep showing verification screen
343+
authUI.updateAuthState(
344+
AuthState.RequiresEmailVerification(
345+
user = user,
346+
email = user.email ?: ""
347+
)
348+
)
349+
}
350+
}
327351
} catch (e: Exception) {
328352
Log.e("FirebaseAuthScreen", "Failed to refresh user", e)
329353
}

auth/src/main/java/com/firebase/ui/auth/compose/ui/screens/email/EmailAuthScreen.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,17 @@ fun EmailAuthScreen(
310310
} else {
311311
DefaultEmailAuthContent(
312312
configuration = configuration,
313-
state = state
313+
state = state,
314+
onCancel = onCancel
314315
)
315316
}
316317
}
317318

318319
@Composable
319320
private fun DefaultEmailAuthContent(
320321
configuration: AuthUIConfiguration,
321-
state: EmailAuthContentState
322+
state: EmailAuthContentState,
323+
onCancel: () -> Unit
322324
) {
323325
when (state.mode) {
324326
EmailAuthMode.SignIn -> {
@@ -332,7 +334,8 @@ private fun DefaultEmailAuthContent(
332334
onPasswordChange = state.onPasswordChange,
333335
onSignInClick = state.onSignInClick,
334336
onGoToSignUp = state.onGoToSignUp,
335-
onGoToResetPassword = state.onGoToResetPassword
337+
onGoToResetPassword = state.onGoToResetPassword,
338+
onNavigateBack = onCancel
336339
)
337340
}
338341

auth/src/main/java/com/firebase/ui/auth/compose/ui/screens/email/SignInUI.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ import androidx.compose.foundation.layout.size
2525
import androidx.compose.foundation.layout.width
2626
import androidx.compose.foundation.rememberScrollState
2727
import androidx.compose.foundation.verticalScroll
28+
import androidx.compose.material.icons.Icons
29+
import androidx.compose.material.icons.automirrored.filled.ArrowBack
2830
import androidx.compose.material3.AlertDialog
2931
import androidx.compose.material3.Button
3032
import androidx.compose.material3.CircularProgressIndicator
3133
import androidx.compose.material3.ExperimentalMaterial3Api
34+
import androidx.compose.material3.Icon
35+
import androidx.compose.material3.IconButton
3236
import androidx.compose.material3.MaterialTheme
3337
import androidx.compose.material3.Scaffold
3438
import androidx.compose.material3.Text
@@ -73,6 +77,7 @@ fun SignInUI(
7377
onSignInClick: () -> Unit,
7478
onGoToSignUp: () -> Unit,
7579
onGoToResetPassword: () -> Unit,
80+
onNavigateBack: (() -> Unit)? = null,
7681
) {
7782
val provider = configuration.providers.filterIsInstance<AuthProvider.Email>().first()
7883
val stringProvider = LocalAuthUIStringProvider.current
@@ -138,6 +143,16 @@ fun SignInUI(
138143
modifier = Modifier.semantics { heading() }
139144
)
140145
},
146+
navigationIcon = {
147+
if (onNavigateBack != null) {
148+
IconButton(onClick = onNavigateBack) {
149+
Icon(
150+
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
151+
contentDescription = stringProvider.backAction
152+
)
153+
}
154+
}
155+
},
141156
colors = AuthUITheme.topAppBarColors
142157
)
143158
},

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ class HighLevelApiDemoActivity : ComponentActivity() {
5656
serverClientId = "771411398215-o39fujhds88bs4mb5ai7u6o73g86fspp.apps.googleusercontent.com",
5757
)
5858
)
59+
// Email/Password Sign-in
60+
provider(
61+
AuthProvider.Email(
62+
isDisplayNameRequired = true,
63+
isEmailLinkSignInEnabled = false,
64+
isNewAccountsAllowed = true,
65+
minimumPasswordLength = 8,
66+
passwordValidationRules = listOf(
67+
PasswordRule.MinimumLength(8),
68+
PasswordRule.RequireLowercase,
69+
PasswordRule.RequireUppercase,
70+
),
71+
emailLinkActionCodeSettings = null,
72+
buttonLabel = "Sign in with Email"
73+
)
74+
)
75+
// Email Link Sign-in (passwordless)
5976
provider(
6077
AuthProvider.Email(
6178
isDisplayNameRequired = true,
@@ -76,7 +93,8 @@ class HighLevelApiDemoActivity : ComponentActivity() {
7693
PasswordRule.MinimumLength(8),
7794
PasswordRule.RequireLowercase,
7895
PasswordRule.RequireUppercase,
79-
)
96+
),
97+
buttonLabel = "Sign in with Email Link"
8098
)
8199
)
82100
provider(

0 commit comments

Comments
 (0)