Skip to content

feat(auth): add reauthentication flow with automatic operation retry#2332

Open
demolaf wants to merge 5 commits into
version-10.0.0-beta03from
feat/reauthentication-flow
Open

feat(auth): add reauthentication flow with automatic operation retry#2332
demolaf wants to merge 5 commits into
version-10.0.0-beta03from
feat/reauthentication-flow

Conversation

@demolaf

@demolaf demolaf commented Jun 5, 2026

Copy link
Copy Markdown
Member

Closes #563 .

Implements the reauthentication flow.

FirebaseAuthScreen now handles AuthState.ReauthenticationRequired internally. When this state is emitted, it automatically shows a bottom sheet scoped to only the providers already linked to the current user, disables new account creation, and retries the original operation on successful reauthentication — all without any extra wiring from the caller.

Two new APIs expose this to apps:

withReauth — wraps any sensitive Firebase operation. If it throws FirebaseAuthRecentLoginRequiredException, it emits ReauthenticationRequired with the operation attached as a retry. FirebaseAuthScreen picks it up, shows the reauth sheet, and re-runs the operation automatically on success.

lifecycleScope.launch {
    authUI.withReauth(context, reason = "Verify your identity to delete your account") {
        user.delete().await()
    }
}

createReauthFlow — activity-based alternative returning an AuthFlowController for apps that want an explicit, launcher-style reauth flow scoped to the current user's linked providers.

FirebaseAuthScreen also gains a reauthContent slot for apps that want to supply their own reauth UI instead of the default bottom sheet.

Preview

Reauthentication.Demo.webm

@demolaf demolaf changed the title wip feat(auth): add reauthentication flow with automatic operation retry Jun 5, 2026
@demolaf demolaf marked this pull request as draft June 5, 2026 10:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a reauthentication flow to the FirebaseUI Auth library, which is required before performing sensitive operations such as account deletion. It adds a new AuthState.ReauthenticationRequired state, a createReauthFlow method in FirebaseAuthUI, and updates the email and OAuth providers to support reauthentication. Additionally, it integrates a reauthentication bottom sheet in FirebaseAuthScreen and updates the demo application to demonstrate account deletion. The review feedback highlights three key improvement opportunities: wrapping the retry(context) invocation in a try-catch block within FirebaseAuthScreen to prevent potential crashes from unhandled exceptions, and replacing unsafe double-bang (!!) operators on auth.currentUser with defensive null checks in both EmailAuthProvider+FirebaseAuthUI.kt and OAuthProvider+FirebaseAuthUI.kt.

Comment thread auth/src/main/java/com/firebase/ui/auth/ui/screens/FirebaseAuthScreen.kt Outdated
@demolaf demolaf linked an issue Jun 5, 2026 that may be closed by this pull request
@demolaf demolaf marked this pull request as ready for review June 8, 2026 15:55
demolaf added 4 commits June 8, 2026 17:16
# Conflicts:
#	auth/src/main/java/com/firebase/ui/auth/configuration/auth_provider/EmailAuthProvider+FirebaseAuthUI.kt
#	auth/src/main/java/com/firebase/ui/auth/ui/screens/FirebaseAuthScreen.kt
Adds AuthState.ReauthenticationRequired, withReauth(), and createReauthFlow()
to support sensitive operations that require recent sign-in. FirebaseAuthUI.delete()
and withReauth() automatically catch FirebaseAuthRecentLoginRequiredException,
emit the new state carrying the original operation as retryOperation, and
FirebaseAuthScreen presents a ModalBottomSheet overlay scoped to the user's
linked providers — no navigation away from the authenticated screen. On successful
reauthentication the original operation is retried automatically.
@demolaf demolaf force-pushed the feat/reauthentication-flow branch from 41c17b7 to a9952cc Compare June 8, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an AuthUI.reauthenticate() function

1 participant