Skip to content

refactor(auth)!: decouple reauthentication from the FirebaseAuthUI shared state flow - #2478

Open
demolaf wants to merge 15 commits into
version-10.0.0-beta05from
refactor/reauth-remove-shared-flow-coupling
Open

refactor(auth)!: decouple reauthentication from the FirebaseAuthUI shared state flow#2478
demolaf wants to merge 15 commits into
version-10.0.0-beta05from
refactor/reauth-remove-shared-flow-coupling

Conversation

@demolaf

@demolaf demolaf commented Sep 4, 2026

Copy link
Copy Markdown
Member

FirebaseAuthUI was the SDK entry point, the process-wide AuthState channel and the reauthentication session store all at once. Reauthentication requests now travel on their own channel, provider code emits to an AuthFlowScope sink instead of the singleton's flow, and the phase machine lives in a composition-scoped holder — nine members deleted from FirebaseAuthUI, none added.

withReauth no longer retains the caller's lambda on a process-scoped singleton: it raises a request, suspends on a resolver, and retries on the caller's own coroutine. delete() goes through the same path instead of publishing Required and throwing.

  • AuthFlowScope.kt: provider extensions move off FirebaseAuthUI, so provider code can no longer reach the public state flow at all — the isolation is compiler-held rather than review-held.
  • ReauthFlowState.kt: the phase machine, scoped to one FirebaseAuthScreen's composition. Aborted now clears the phase and resolves the caller under both hosts.
  • Added SignInStateSequenceTest and ReauthFlowStateTest, plus emulator-backed e2e coverage for a password change and an account deletion through reauthentication.

⚠️ Breaking Changes

  • AuthState.Reauthentication.Required.retryOperation is removed outright — pre-GA, zero external usage, no shim.
  • AuthState.Reauthentication.Required's (user, reason) constructor is now internal. Raising a request is withReauth/delete()'s job; constructing one yourself no longer did anything.
  • A declined reauthentication throws AuthException.AuthCancelledException instead of returning quietly, and delete() reports that rather than InvalidCredentialsException.
  • Publishing AuthState.Reauthentication.Required to authStateFlow() yourself no longer raises a request; only withReauth and delete() do.
  • Rotation during the reauth sheet abandons the pending operation unless the caller launched from a scope that survives it.

Maintainer note: Fixes internal CPRN-413

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

Copy link
Copy Markdown
Contributor

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 refactors the reauthentication flow in FirebaseUI Auth to use a composition-scoped AuthFlowScope and coroutine-based suspension (CompletableDeferred) instead of process-local callbacks on FirebaseAuthUI. This prevents sensitive operations from being lost or executed multiple times during Activity recreation. Various auth providers have been updated to emit states through this new scope. Feedback is provided to improve code safety in authUserState by avoiding the !! operator on user.email through smart casting.

Comment thread auth/src/main/java/com/firebase/ui/auth/AuthFlowScope.kt Outdated
@demolaf
demolaf marked this pull request as ready for review September 4, 2026 11:37
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.

1 participant