-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Version 10.0.0 beta03 #2315
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
Draft
russellwheatley
wants to merge
2
commits into
master
Choose a base branch
from
version-10.0.0-beta03
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Version 10.0.0 beta03 #2315
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,8 @@ import com.firebase.ui.auth.configuration.theme.AuthUITheme | |||||
| import com.firebase.ui.auth.ui.screens.AuthSuccessUiContext | ||||||
| import com.firebase.ui.auth.ui.screens.FirebaseAuthScreen | ||||||
| import com.firebase.ui.auth.util.EmailLinkConstants | ||||||
| import com.firebase.ui.auth.util.displayIdentifier | ||||||
| import com.firebase.ui.auth.util.getDisplayEmail | ||||||
| import com.google.firebase.auth.actionCodeSettings | ||||||
|
|
||||||
| class HighLevelApiDemoActivity : ComponentActivity() { | ||||||
|
|
@@ -211,7 +213,7 @@ private fun AppAuthenticatedContent( | |||||
| when (state) { | ||||||
| is AuthState.Success -> { | ||||||
| val user = uiContext.authUI.getCurrentUser() | ||||||
| val identifier = user?.email ?: user?.phoneNumber ?: user?.uid.orEmpty() | ||||||
| val identifier = user.displayIdentifier() | ||||||
| Column( | ||||||
| modifier = Modifier.fillMaxSize(), | ||||||
| horizontalAlignment = Alignment.CenterHorizontally, | ||||||
|
|
@@ -263,7 +265,7 @@ private fun AppAuthenticatedContent( | |||||
| } | ||||||
|
|
||||||
| is AuthState.RequiresEmailVerification -> { | ||||||
| val email = uiContext.authUI.getCurrentUser()?.email ?: stringProvider.emailProvider | ||||||
| val email = uiContext.authUI.getCurrentUser().getDisplayEmail(stringProvider.emailProvider) | ||||||
|
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. In the
Suggested change
|
||||||
| Column( | ||||||
| modifier = Modifier.fillMaxSize(), | ||||||
| horizontalAlignment = Alignment.CenterHorizontally, | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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.util | ||
|
|
||
| import com.google.firebase.auth.FirebaseUser | ||
|
|
||
| /** | ||
| * Returns the best available display identifier for the user, trying each field in order: | ||
| * email → phoneNumber → displayName → uid. | ||
| * | ||
| * Each field is checked for blank (not just null) so that an empty string returned by the | ||
| * Firebase SDK falls through to the next candidate rather than being displayed as-is. | ||
| * Returns an empty string if the user is null. | ||
| */ | ||
| fun FirebaseUser?.displayIdentifier(): String = | ||
| this?.email?.takeIf { it.isNotBlank() } | ||
| ?: this?.phoneNumber?.takeIf { it.isNotBlank() } | ||
| ?: this?.displayName?.takeIf { it.isNotBlank() } | ||
| ?: this?.uid | ||
| ?: "" | ||
|
|
||
| /** | ||
| * Returns the user's email if it is non-blank, otherwise returns the provided [fallback]. | ||
| */ | ||
| fun FirebaseUser?.getDisplayEmail(fallback: String): String = | ||
| this?.email?.takeIf { it.isNotBlank() } ?: fallback |
118 changes: 118 additions & 0 deletions
118
auth/src/test/java/com/firebase/ui/auth/ui/screens/FirebaseAuthScreenRouteTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package com.firebase.ui.auth.ui.screens | ||
|
|
||
| import android.content.Context | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import com.firebase.ui.auth.configuration.authUIConfiguration | ||
| import com.firebase.ui.auth.configuration.auth_provider.AuthProvider | ||
| import com.google.common.truth.Truth.assertThat | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(manifest = Config.NONE) | ||
| class FirebaseAuthScreenRouteTest { | ||
|
|
||
| private lateinit var applicationContext: Context | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| applicationContext = ApplicationProvider.getApplicationContext() | ||
| } | ||
|
|
||
| @Test | ||
| fun `single email provider starts at email route`() { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Email( | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| assertThat(getStartRoute(configuration)).isEqualTo(AuthRoute.Email) | ||
| } | ||
|
|
||
| @Test | ||
| fun `single phone provider starts at phone route`() { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Phone( | ||
| defaultNumber = null, | ||
| defaultCountryCode = null, | ||
| allowedCountries = null | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| assertThat(getStartRoute(configuration)).isEqualTo(AuthRoute.Phone) | ||
| } | ||
|
|
||
| @Test | ||
| fun `single google provider starts at method picker`() { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Google( | ||
| scopes = emptyList(), | ||
| serverClientId = "test-client-id" | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| assertThat(getStartRoute(configuration)).isEqualTo(AuthRoute.MethodPicker) | ||
| } | ||
|
|
||
| @Test | ||
| fun `single email provider shows picker when always shown is enabled`() { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Email( | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| ) | ||
| } | ||
| isProviderChoiceAlwaysShown = true | ||
| } | ||
|
|
||
| assertThat(getStartRoute(configuration)).isEqualTo(AuthRoute.MethodPicker) | ||
| } | ||
|
|
||
| @Test | ||
| fun `multiple providers start at method picker`() { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Email( | ||
| emailLinkActionCodeSettings = null, | ||
| passwordValidationRules = emptyList() | ||
| ) | ||
| ) | ||
| provider( | ||
| AuthProvider.Phone( | ||
| defaultNumber = null, | ||
| defaultCountryCode = null, | ||
| allowedCountries = null | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| assertThat(getStartRoute(configuration)).isEqualTo(AuthRoute.MethodPicker) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the
stateis already smart-cast toAuthState.Successin this block, you can usestate.userdirectly instead of relying on theuservariable retrieved fromauthUI.getCurrentUser(). This is more idiomatic as it ensures you are using the specific user instance that triggered the current state emission.