-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(auth): pre-fill email when "Continue as" button is tapped (#2423) #2425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: version-10.0.0-beta04
Are you sure you want to change the base?
Changes from all commits
5583dca
6268a0d
59df1d6
d9f7c41
10809b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,7 @@ fun EmailAuthScreen( | |
| onSuccess: (AuthResult) -> Unit, | ||
| onError: (AuthException) -> Unit, | ||
| onCancel: () -> Unit, | ||
| prefillEmail: String? = null, | ||
| content: @Composable ((EmailAuthContentState) -> Unit)? = null, | ||
| ) { | ||
| val provider = configuration.providers.filterIsInstance<AuthProvider.Email>().first() | ||
|
|
@@ -150,7 +151,7 @@ fun EmailAuthScreen( | |
| } | ||
| val mode = rememberSaveable { mutableStateOf(initialMode) } | ||
| val displayNameValue = rememberSaveable { mutableStateOf("") } | ||
| val emailTextValue = rememberSaveable { mutableStateOf("") } | ||
| val emailTextValue = rememberSaveable { mutableStateOf(prefillEmail ?: "") } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add a unit test that asserts the email is pre-filled. there's already a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @just1and0 this doesn't test from |
||
| val passwordTextValue = rememberSaveable { mutableStateOf("") } | ||
| val confirmPasswordTextValue = rememberSaveable { mutableStateOf("") } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Copyright 2025 Google Inc. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the | ||
| * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.firebase.ui.auth.ui.screens.email | ||
|
|
||
| import android.content.Context | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.test.assertTextContains | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import com.firebase.ui.auth.configuration.authUIConfiguration | ||
| import com.firebase.ui.auth.configuration.auth_provider.AuthProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.AuthUIStringProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.DefaultAuthUIStringProvider | ||
| import com.firebase.ui.auth.configuration.string_provider.LocalAuthUIStringProvider | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| @Config(sdk = [34]) | ||
| @RunWith(RobolectricTestRunner::class) | ||
| class SignInUITest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private lateinit var applicationContext: Context | ||
| private lateinit var stringProvider: AuthUIStringProvider | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| applicationContext = ApplicationProvider.getApplicationContext() | ||
| stringProvider = DefaultAuthUIStringProvider(applicationContext) | ||
| } | ||
|
|
||
| @Test | ||
| fun `email field is pre-filled when initial email value is provided`() { | ||
| val prefillEmail = "user@example.com" | ||
| val provider = AuthProvider.Email( | ||
| isDisplayNameRequired = false, | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { provider(provider) } | ||
| } | ||
|
|
||
| composeTestRule.setContent { | ||
| CompositionLocalProvider(LocalAuthUIStringProvider provides stringProvider) { | ||
| SignInUI( | ||
| configuration = configuration, | ||
| isLoading = false, | ||
| emailSignInLinkSent = false, | ||
| email = prefillEmail, | ||
| password = "", | ||
| onEmailChange = { }, | ||
| onPasswordChange = { }, | ||
| onRetrievedCredential = { }, | ||
| onSignInClick = { }, | ||
| onGoToSignUp = { }, | ||
| onGoToResetPassword = { }, | ||
| onGoToEmailLinkSignIn = { }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithText(prefillEmail).assertExists() | ||
| } | ||
|
|
||
| @Test | ||
| fun `email field is empty when no initial email value is provided`() { | ||
| val provider = AuthProvider.Email( | ||
| isDisplayNameRequired = false, | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { provider(provider) } | ||
| } | ||
|
|
||
| composeTestRule.setContent { | ||
| CompositionLocalProvider(LocalAuthUIStringProvider provides stringProvider) { | ||
| SignInUI( | ||
| configuration = configuration, | ||
| isLoading = false, | ||
| emailSignInLinkSent = false, | ||
| email = "", | ||
| password = "", | ||
| onEmailChange = { }, | ||
| onPasswordChange = { }, | ||
| onRetrievedCredential = { }, | ||
| onSignInClick = { }, | ||
| onGoToSignUp = { }, | ||
| onGoToResetPassword = { }, | ||
| onGoToEmailLinkSignIn = { }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithText("user@example.com").assertDoesNotExist() | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.