feat(auth): add reauthentication flow with automatic operation retry#2332
feat(auth): add reauthentication flow with automatic operation retry#2332demolaf wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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.
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.
41c17b7 to
a9952cc
Compare
Closes #563 .
Implements the reauthentication flow.
FirebaseAuthScreennow handlesAuthState.ReauthenticationRequiredinternally. 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 throwsFirebaseAuthRecentLoginRequiredException, it emitsReauthenticationRequiredwith the operation attached as a retry.FirebaseAuthScreenpicks 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 anAuthFlowControllerfor apps that want an explicit, launcher-style reauth flow scoped to the current user's linked providers.FirebaseAuthScreenalso gains areauthContentslot for apps that want to supply their own reauth UI instead of the default bottom sheet.Preview
Reauthentication.Demo.webm