Skip to content

Commit 2323cbf

Browse files
committed
feat: extract routes from example app to main library
1 parent 5a13fbc commit 2323cbf

File tree

19 files changed

+1427
-939
lines changed

19 files changed

+1427
-939
lines changed

auth/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ dependencies {
9797
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
9898
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
9999
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
100+
implementation("androidx.navigation:navigation-compose:2.8.3")
101+
implementation("com.google.zxing:core:3.5.3")
100102
implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1")
101103
annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)
102104

auth/src/main/java/com/firebase/ui/auth/compose/configuration/string_provider/AuthUIStringProvider.kt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,87 @@ interface AuthUIStringProvider {
236236
/** Loading progress text */
237237
val progressDialogLoading: String
238238

239+
/** Label shown when the user is signed in. String should contain a single %s placeholder. */
240+
fun signedInAs(userIdentifier: String): String
241+
242+
/** Action text for managing multi-factor authentication settings. */
243+
val manageMfaAction: String
244+
245+
/** Action text for signing out. */
246+
val signOutAction: String
247+
248+
/** Instruction shown when the user must verify their email. Accepts the email value. */
249+
fun verifyEmailInstruction(email: String): String
250+
251+
/** Action text for resending the verification email. */
252+
val resendVerificationEmailAction: String
253+
254+
/** Action text once the user has verified their email. */
255+
val verifiedEmailAction: String
256+
257+
/** Message shown when profile completion is required. */
258+
val profileCompletionMessage: String
259+
260+
/** Message listing missing profile fields. Accepts a comma-separated list. */
261+
fun profileMissingFieldsMessage(fields: String): String
262+
263+
/** Action text for skipping an optional step. */
264+
val skipAction: String
265+
266+
/** Action text for removing an item (for example, an MFA factor). */
267+
val removeAction: String
268+
269+
/** Action text for navigating back. */
270+
val backAction: String
271+
272+
/** Action text for confirming verification. */
273+
val verifyAction: String
274+
275+
/** Action text for choosing a different factor during MFA challenge. */
276+
val useDifferentMethodAction: String
277+
278+
/** Action text for confirming recovery codes have been saved. */
279+
val recoveryCodesSavedAction: String
280+
281+
/** Label for secret key text displayed during TOTP setup. */
282+
val secretKeyLabel: String
283+
284+
/** Label for verification code input fields. */
285+
val verificationCodeLabel: String
286+
287+
/** Generic identity verified confirmation message. */
288+
val identityVerifiedMessage: String
289+
290+
/** Title for the manage MFA screen. */
291+
val mfaManageFactorsTitle: String
292+
293+
/** Helper description for the manage MFA screen. */
294+
val mfaManageFactorsDescription: String
295+
296+
/** Header for the list of currently enrolled MFA factors. */
297+
val mfaActiveMethodsTitle: String
298+
299+
/** Header for the list of available MFA factors to enroll. */
300+
val mfaAddNewMethodTitle: String
301+
302+
/** Message shown when all factors are already enrolled. */
303+
val mfaAllMethodsEnrolledMessage: String
304+
305+
/** Label for SMS MFA factor. */
306+
val smsAuthenticationLabel: String
307+
308+
/** Label for authenticator-app MFA factor. */
309+
val totpAuthenticationLabel: String
310+
311+
/** Label used when the factor type is unknown. */
312+
val unknownMethodLabel: String
313+
314+
/** Label describing the enrollment date. Accepts a formatted date string. */
315+
fun enrolledOnDateLabel(date: String): String
316+
317+
/** Description displayed during authenticator app setup. */
318+
val setupAuthenticatorDescription: String
319+
239320
/** Network error message */
240321
val noInternet: String
241322

@@ -339,4 +420,20 @@ interface AuthUIStringProvider {
339420

340421
/** Generic error message for MFA enrollment failures */
341422
val mfaErrorGeneric: String
423+
424+
// Re-authentication Dialog
425+
/** Title displayed in the re-authentication dialog. */
426+
val reauthDialogTitle: String
427+
428+
/** Descriptive message shown in the re-authentication dialog. */
429+
val reauthDialogMessage: String
430+
431+
/** Label showing the account email being re-authenticated. */
432+
fun reauthAccountLabel(email: String): String
433+
434+
/** Error message shown when the provided password is incorrect. */
435+
val incorrectPasswordError: String
436+
437+
/** General error message for re-authentication failures. */
438+
val reauthGenericError: String
342439
}

auth/src/main/java/com/firebase/ui/auth/compose/configuration/string_provider/DefaultAuthUIStringProvider.kt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,87 @@ class DefaultAuthUIStringProvider(
235235
get() = localizedContext.getString(R.string.fui_required_field)
236236
override val progressDialogLoading: String
237237
get() = localizedContext.getString(R.string.fui_progress_dialog_loading)
238+
239+
override fun signedInAs(userIdentifier: String): String =
240+
localizedContext.getString(R.string.fui_signed_in_as, userIdentifier)
241+
242+
override val manageMfaAction: String
243+
get() = localizedContext.getString(R.string.fui_manage_mfa_action)
244+
245+
override val signOutAction: String
246+
get() = localizedContext.getString(R.string.fui_sign_out_action)
247+
248+
override fun verifyEmailInstruction(email: String): String =
249+
localizedContext.getString(R.string.fui_verify_email_instruction, email)
250+
251+
override val resendVerificationEmailAction: String
252+
get() = localizedContext.getString(R.string.fui_resend_verification_email_action)
253+
254+
override val verifiedEmailAction: String
255+
get() = localizedContext.getString(R.string.fui_verified_email_action)
256+
257+
override val profileCompletionMessage: String
258+
get() = localizedContext.getString(R.string.fui_profile_completion_message)
259+
260+
override fun profileMissingFieldsMessage(fields: String): String =
261+
localizedContext.getString(R.string.fui_profile_missing_fields_message, fields)
262+
263+
override val skipAction: String
264+
get() = localizedContext.getString(R.string.fui_skip_action)
265+
266+
override val removeAction: String
267+
get() = localizedContext.getString(R.string.fui_remove_action)
268+
269+
override val backAction: String
270+
get() = localizedContext.getString(R.string.fui_back_action)
271+
272+
override val verifyAction: String
273+
get() = localizedContext.getString(R.string.fui_verify_action)
274+
275+
override val useDifferentMethodAction: String
276+
get() = localizedContext.getString(R.string.fui_use_different_method_action)
277+
278+
override val recoveryCodesSavedAction: String
279+
get() = localizedContext.getString(R.string.fui_recovery_codes_saved_action)
280+
281+
override val secretKeyLabel: String
282+
get() = localizedContext.getString(R.string.fui_secret_key_label)
283+
284+
override val verificationCodeLabel: String
285+
get() = localizedContext.getString(R.string.fui_verification_code_label)
286+
287+
override val identityVerifiedMessage: String
288+
get() = localizedContext.getString(R.string.fui_identity_verified_message)
289+
290+
override val mfaManageFactorsTitle: String
291+
get() = localizedContext.getString(R.string.fui_mfa_manage_factors_title)
292+
293+
override val mfaManageFactorsDescription: String
294+
get() = localizedContext.getString(R.string.fui_mfa_manage_factors_description)
295+
296+
override val mfaActiveMethodsTitle: String
297+
get() = localizedContext.getString(R.string.fui_mfa_active_methods_title)
298+
299+
override val mfaAddNewMethodTitle: String
300+
get() = localizedContext.getString(R.string.fui_mfa_add_new_method_title)
301+
302+
override val mfaAllMethodsEnrolledMessage: String
303+
get() = localizedContext.getString(R.string.fui_mfa_all_methods_enrolled_message)
304+
305+
override val smsAuthenticationLabel: String
306+
get() = localizedContext.getString(R.string.fui_mfa_label_sms_authentication)
307+
308+
override val totpAuthenticationLabel: String
309+
get() = localizedContext.getString(R.string.fui_mfa_label_totp_authentication)
310+
311+
override val unknownMethodLabel: String
312+
get() = localizedContext.getString(R.string.fui_mfa_label_unknown_method)
313+
314+
override fun enrolledOnDateLabel(date: String): String =
315+
localizedContext.getString(R.string.fui_mfa_enrolled_on, date)
316+
317+
override val setupAuthenticatorDescription: String
318+
get() = localizedContext.getString(R.string.fui_mfa_setup_authenticator_description)
238319
override val noInternet: String
239320
get() = localizedContext.getString(R.string.fui_no_internet)
240321

@@ -319,4 +400,19 @@ class DefaultAuthUIStringProvider(
319400
get() = localizedContext.getString(R.string.fui_mfa_error_network)
320401
override val mfaErrorGeneric: String
321402
get() = localizedContext.getString(R.string.fui_mfa_error_generic)
403+
404+
override val reauthDialogTitle: String
405+
get() = localizedContext.getString(R.string.fui_reauth_dialog_title)
406+
407+
override val reauthDialogMessage: String
408+
get() = localizedContext.getString(R.string.fui_reauth_dialog_message)
409+
410+
override fun reauthAccountLabel(email: String): String =
411+
localizedContext.getString(R.string.fui_reauth_account_label, email)
412+
413+
override val incorrectPasswordError: String
414+
get() = localizedContext.getString(R.string.fui_incorrect_password_error)
415+
416+
override val reauthGenericError: String
417+
get() = localizedContext.getString(R.string.fui_reauth_generic_error)
322418
}

auth/src/main/java/com/firebase/ui/auth/compose/mfa/MfaEnrollmentContentState.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ data class MfaEnrollmentContentState(
8585
/** Optional error message to display. `null` if no error. */
8686
val error: String? = null,
8787

88+
/** The last exception encountered during enrollment, if available. */
89+
val exception: Exception? = null,
90+
8891
/** Callback to navigate to the previous step. */
8992
val onBackClick: () -> Unit = {},
9093

composeapp/src/main/java/com/firebase/composeapp/ui/components/QrCodeImage.kt renamed to auth/src/main/java/com/firebase/ui/auth/compose/ui/components/QrCodeImage.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.firebase.composeapp.ui.components
15+
package com.firebase.ui.auth.compose.ui.components
1616

1717
import android.graphics.Bitmap
1818
import androidx.compose.foundation.Image
1919
import androidx.compose.foundation.background
2020
import androidx.compose.foundation.layout.Box
2121
import androidx.compose.foundation.layout.size
22-
import androidx.compose.material3.MaterialTheme
2322
import androidx.compose.runtime.Composable
2423
import androidx.compose.runtime.remember
2524
import androidx.compose.ui.Alignment
@@ -34,13 +33,16 @@ import com.google.zxing.WriterException
3433
import com.google.zxing.qrcode.QRCodeWriter
3534

3635
/**
37-
* Composable that displays a QR code image generated from the provided content.
36+
* Renders a QR code from the provided content string.
3837
*
39-
* @param content The string content to encode in the QR code (e.g., TOTP URI)
40-
* @param modifier Modifier to be applied to the QR code image
41-
* @param size The size (width and height) of the QR code image
42-
* @param foregroundColor The color of the QR code pixels (default: black)
43-
* @param backgroundColor The background color of the QR code (default: white)
38+
* This component is typically used to display TOTP enrollment URIs. The QR code is generated on the
39+
* fly and memoized for the given [content].
40+
*
41+
* @param content The string content to encode into the QR code (for example the TOTP URI).
42+
* @param modifier Optional [Modifier] applied to the QR container.
43+
* @param size The size of the QR code square in density-independent pixels.
44+
* @param foregroundColor Color used to render the QR pixels (defaults to black).
45+
* @param backgroundColor Background color for the QR code (defaults to white).
4446
*/
4547
@Composable
4648
fun QrCodeImage(
@@ -53,7 +55,7 @@ fun QrCodeImage(
5355
val bitmap = remember(content, size, foregroundColor, backgroundColor) {
5456
generateQrCodeBitmap(
5557
content = content,
56-
sizePx = (size.value * 2).toInt(), // 2x for better resolution
58+
sizePx = (size.value * 2).toInt(), // Render at 2x for better scaling quality.
5759
foregroundColor = foregroundColor,
5860
backgroundColor = backgroundColor
5961
)
@@ -75,15 +77,6 @@ fun QrCodeImage(
7577
}
7678
}
7779

78-
/**
79-
* Generates a QR code bitmap from the provided content.
80-
*
81-
* @param content The string to encode
82-
* @param sizePx The size of the bitmap in pixels
83-
* @param foregroundColor The color for the QR code pixels
84-
* @param backgroundColor The background color
85-
* @return A Bitmap containing the QR code, or null if generation fails
86-
*/
8780
private fun generateQrCodeBitmap(
8881
content: String,
8982
sizePx: Int,
@@ -93,7 +86,7 @@ private fun generateQrCodeBitmap(
9386
return try {
9487
val qrCodeWriter = QRCodeWriter()
9588
val hints = mapOf(
96-
EncodeHintType.MARGIN to 1 // Minimal margin
89+
EncodeHintType.MARGIN to 1 // Small margin keeps QR code compact while remaining scannable.
9790
)
9891

9992
val bitMatrix = qrCodeWriter.encode(
@@ -132,7 +125,6 @@ private fun generateQrCodeBitmap(
132125

133126
bitmap
134127
} catch (e: WriterException) {
135-
e.printStackTrace()
136128
null
137129
}
138130
}

0 commit comments

Comments
 (0)