Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@

package com.firebase.ui.auth.compose.configuration

import android.content.Context
import java.util.Locale
import com.google.firebase.auth.ActionCodeSettings
import androidx.compose.ui.graphics.vector.ImageVector
import com.firebase.ui.auth.compose.configuration.stringprovider.AuthUIStringProvider
import com.firebase.ui.auth.compose.configuration.stringprovider.DefaultAuthUIStringProvider

fun actionCodeSettings(
block: ActionCodeSettings.Builder.() -> Unit
) = ActionCodeSettings.newBuilder().apply(block).build()
fun actionCodeSettings(block: ActionCodeSettings.Builder.() -> Unit) =
ActionCodeSettings.newBuilder().apply(block).build()

fun authUIConfiguration(block: AuthUIConfigurationBuilder.() -> Unit): AuthUIConfiguration {
val builder = AuthUIConfigurationBuilder()
builder.block()
return builder.build()
}
fun authUIConfiguration(block: AuthUIConfigurationBuilder.() -> Unit) =
AuthUIConfigurationBuilder().apply(block).build()

@DslMarker
annotation class AuthUIConfigurationDsl

@AuthUIConfigurationDsl
class AuthUIConfigurationBuilder {
var context: Context? = null
private val providers = mutableListOf<AuthProvider>()
var theme: AuthUITheme = AuthUITheme.Default
var stringProvider: AuthUIStringProvider? = null
var locale: Locale? = null
var stringProvider: AuthUIStringProvider? = null
var isCredentialManagerEnabled: Boolean = true
var isMfaEnabled: Boolean = true
var isAnonymousUpgradeEnabled: Boolean = false
Expand All @@ -48,36 +48,16 @@ class AuthUIConfigurationBuilder {
var isDisplayNameRequired: Boolean = true
var isProviderChoiceAlwaysShown: Boolean = false

fun providers(block: AuthProvidersBuilder.() -> Unit) {
val builder = AuthProvidersBuilder()
builder.block()
providers.addAll(builder.build())
}
fun providers(block: AuthProvidersBuilder.() -> Unit) =
providers.addAll(AuthProvidersBuilder().apply(block).build())

internal fun build(): AuthUIConfiguration {
validate()
return AuthUIConfiguration(
providers = providers.toList(),
theme = theme,
stringProvider = stringProvider,
locale = locale,
isCredentialManagerEnabled = isCredentialManagerEnabled,
isMfaEnabled = isMfaEnabled,
isAnonymousUpgradeEnabled = isAnonymousUpgradeEnabled,
tosUrl = tosUrl,
privacyPolicyUrl = privacyPolicyUrl,
logo = logo,
actionCodeSettings = actionCodeSettings,
isNewEmailAccountsAllowed = isNewEmailAccountsAllowed,
isDisplayNameRequired = isDisplayNameRequired,
isProviderChoiceAlwaysShown = isProviderChoiceAlwaysShown
)
}
val context = requireNotNull(context) {
"Application context is required"
}

private fun validate() {
// At least one provider
if (providers.isEmpty()) {
throw IllegalArgumentException("At least one provider must be configured")
require(providers.isNotEmpty()) {
"At least one provider must be configured"
}

// No unsupported providers
Expand Down Expand Up @@ -113,13 +93,36 @@ class AuthUIConfigurationBuilder {
else -> null
}
}

return AuthUIConfiguration(
context = context,
providers = providers.toList(),
theme = theme,
locale = locale,
stringProvider = stringProvider ?: DefaultAuthUIStringProvider(context, locale),
isCredentialManagerEnabled = isCredentialManagerEnabled,
isMfaEnabled = isMfaEnabled,
isAnonymousUpgradeEnabled = isAnonymousUpgradeEnabled,
tosUrl = tosUrl,
privacyPolicyUrl = privacyPolicyUrl,
logo = logo,
actionCodeSettings = actionCodeSettings,
isNewEmailAccountsAllowed = isNewEmailAccountsAllowed,
isDisplayNameRequired = isDisplayNameRequired,
isProviderChoiceAlwaysShown = isProviderChoiceAlwaysShown
)
}
}

/**
* Configuration object for the authentication flow.
*/
class AuthUIConfiguration(
/**
* Application context
*/
val context: Context,

/**
* The list of enabled authentication providers.
*/
Expand All @@ -131,14 +134,14 @@ class AuthUIConfiguration(
val theme: AuthUITheme = AuthUITheme.Default,

/**
* A custom provider for localized strings.
* The locale for internationalization.
*/
val stringProvider: AuthUIStringProvider? = null,
val locale: Locale? = null,

/**
* The locale for internationalization.
* A custom provider for localized strings.
*/
val locale: Locale? = null,
val stringProvider: AuthUIStringProvider = DefaultAuthUIStringProvider(context, locale),

/**
* Enables integration with Android's Credential Manager API. Defaults to true.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.firebase.ui.auth.compose.configuration

import com.firebase.ui.auth.compose.configuration.stringprovider.AuthUIStringProvider

/**
* An abstract class representing a set of validation rules that can be applied to a password field,
* typically within the [AuthProvider.Email] configuration.
Expand Down
Loading