Skip to content

Commit 9bc2793

Browse files
committed
feat: handle unknown provider and tests
1 parent 8e28099 commit 9bc2793

File tree

3 files changed

+557
-13
lines changed

3 files changed

+557
-13
lines changed

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,28 @@ fun AuthProviderButton(
7575
Row(
7676
verticalAlignment = Alignment.CenterVertically
7777
) {
78-
Image(
79-
painter = providerStyle.icon.painter,
80-
contentDescription = providerText
81-
)
82-
Spacer(modifier = Modifier.width(8.dp))
78+
if (providerStyle.icon != null) {
79+
Image(
80+
painter = providerStyle.icon.painter,
81+
contentDescription = providerText
82+
)
83+
Spacer(modifier = Modifier.width(8.dp))
84+
}
8385
Text(
8486
text = providerText
8587
)
8688
}
8789
}
8890
}
8991

90-
private fun resolveProviderStyle(
92+
internal fun resolveProviderStyle(
9193
provider: AuthProvider,
9294
style: AuthUITheme.ProviderStyle?,
9395
): AuthUITheme.ProviderStyle {
9496
if (style != null) return style
9597

96-
val defaultStyle = requireNotNull(
97-
AuthUITheme.Default.providerStyles[provider.providerId]
98-
) { "No default style found for provider: ${provider.providerId}" }
98+
val defaultStyle =
99+
AuthUITheme.Default.providerStyles[provider.providerId] ?: AuthUITheme.ProviderStyle.Empty
99100

100101
return if (provider is AuthProvider.GenericOAuth) {
101102
AuthUITheme.ProviderStyle(
@@ -108,7 +109,7 @@ private fun resolveProviderStyle(
108109
}
109110
}
110111

111-
private fun resolveProviderLabel(
112+
internal fun resolveProviderLabel(
112113
provider: AuthProvider,
113114
stringProvider: AuthUIStringProvider
114115
): String = when (provider) {
@@ -124,7 +125,7 @@ private fun resolveProviderLabel(
124125
Provider.MICROSOFT -> stringProvider.signInWithMicrosoft
125126
Provider.YAHOO -> stringProvider.signInWithYahoo
126127
Provider.APPLE -> stringProvider.signInWithApple
127-
null -> error("Unknown provider: ${provider.providerId}")
128+
null -> "Unknown Provider"
128129
}
129130
}
130131

@@ -232,5 +233,18 @@ private fun PreviewAuthProviderButton() {
232233
style = AuthUITheme.Default.providerStyles[Provider.MICROSOFT.id],
233234
stringProvider = DefaultAuthUIStringProvider(context)
234235
)
236+
AuthProviderButton(
237+
provider = AuthProvider.GenericOAuth(
238+
providerId = "unknown_provider",
239+
scopes = emptyList(),
240+
customParameters = emptyMap(),
241+
buttonLabel = "Sign in with Lego",
242+
buttonIcon = null,
243+
buttonColor = null,
244+
contentColor = null,
245+
),
246+
onClick = {},
247+
stringProvider = DefaultAuthUIStringProvider(context)
248+
)
235249
}
236250
}

auth/src/main/java/com/firebase/ui/auth/compose/configuration/theme/AuthUITheme.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AuthUITheme(
5959
/**
6060
* The provider's icon.
6161
*/
62-
val icon: AuthUIAsset,
62+
val icon: AuthUIAsset?,
6363

6464
/**
6565
* The background color of the button.
@@ -86,7 +86,19 @@ class AuthUITheme(
8686
* The shadow elevation for the button. Defaults to 2.dp.
8787
*/
8888
val elevation: Dp = 2.dp
89-
)
89+
) {
90+
internal companion object {
91+
/**
92+
* A fallback style for unknown providers with no icon, white background,
93+
* and black text.
94+
*/
95+
val Empty = ProviderStyle(
96+
icon = null,
97+
backgroundColor = Color.White,
98+
contentColor = Color.Black,
99+
)
100+
}
101+
}
90102

91103
companion object {
92104
/**

0 commit comments

Comments
 (0)