Skip to content

feat(auth): add content slots to the reauthentication prompts - #1423

Draft
demolaf wants to merge 1 commit into
fix/mfa-reauthfrom
auth/reauth-content-slots
Draft

demolaf wants to merge 1 commit into
fix/mfa-reauthfrom
auth/reauth-content-slots

Conversation

@demolaf

@demolaf demolaf commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Lets apps draw the password, phone and email link reauthentication prompts with their own content through one .reauthContent modifier. Existing views and the stock UI are unchanged.

Changes

  • EmailReauthScreen, PhoneReauthScreen and EmailLinkReauthScreen own the reauth logic and pass a …ContentState (bindings, actions, isValid, isLoading, localized errorMessage) to their content.
  • DefaultEmailReauthContent, DefaultPhoneReauthContent and DefaultEmailLinkReauthContent hold the stock markup with the stack's theming (authFont, .authCTAButtonStyle()), and EmailReauthView, PhoneReauthView and EmailLinkReauthView now render the screens with them.
  • .reauthContent { prompt in ... } carries the app's content through the environment, so it reaches every sheet withReauthentication presents, from SignedInView to the MFA screens.
  • The confirmation alerts, the OAuth prompt and the second-factor step after reauth stay stock.

API Usage

AuthPickerView { authenticatedApp }
  .reauthContent { prompt in
    switch prompt {
    case let .password(state):
      SecureField("Password", text: state.password)
      Button("Continue", action: state.verify)
        .disabled(!state.isValid || state.isLoading)
      Button("Not now", action: state.cancel)
    default:
      DefaultReauthContent(prompt: prompt)
    }
  }

Preview

Deleting the account with an expired session in the e2e example app (Auth emulator): custom password prompt from the snippet above, stock phone prompt through DefaultReauthContent, and the stock password prompt picking up a Georgia authTypography and purple tint.


Maintainer note: Fixes internal CPRN-608

@demolaf
demolaf added this pull request to stack #1424 October 29, 2026 14:14

@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 FirebaseAuthSwiftUI by introducing reusable screens (EmailLinkReauthScreen, EmailReauthScreen, and PhoneReauthScreen) and default content views, alongside a new reauthContent modifier that allows developers to provide custom UI for reauthentication prompts. It also adds comprehensive unit tests for these components. The review feedback suggests replacing deprecated .foregroundColor modifiers with .foregroundStyle across the new views and refactoring EmailReauthScreen to extract error reporting into a helper method for consistency.

Comment on lines +31 to +34
Image(systemName: "envelope.open.fill")
.font(.system(size: 60))
.foregroundColor(.accentColor)
.padding(.top, 32)

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.

medium

Use .foregroundStyle instead of the deprecated .foregroundColor modifier. In modern SwiftUI (iOS 15+), .foregroundStyle is preferred for setting the color or style of views, and .foregroundStyle(.tint) is the idiomatic way to apply the accent color.

Suggested change
Image(systemName: "envelope.open.fill")
.font(.system(size: 60))
.foregroundColor(.accentColor)
.padding(.top, 32)
Image(systemName: "envelope.open.fill")
.font(.system(size: 60))
.foregroundStyle(.tint)
.padding(.top, 32)

Comment on lines +32 to +34
Image(systemName: "lock.circle.fill")
.font(.system(size: 60))
.foregroundColor(.blue)

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.

medium

Use .foregroundStyle instead of the deprecated .foregroundColor modifier.

Suggested change
Image(systemName: "lock.circle.fill")
.font(.system(size: 60))
.foregroundColor(.blue)
Image(systemName: "lock.circle.fill")
.font(.system(size: 60))
.foregroundStyle(.blue)

Comment on lines +40 to +42
Text(authService.string.forSecurityEnterPasswordMessage)
.font(.body)
.foregroundColor(.secondary)

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.

medium

Use .foregroundStyle instead of the deprecated .foregroundColor modifier.

Suggested change
Text(authService.string.forSecurityEnterPasswordMessage)
.font(.body)
.foregroundColor(.secondary)
Text(authService.string.forSecurityEnterPasswordMessage)
.font(.body)
.foregroundStyle(.secondary)

Comment on lines +32 to +34
Image(systemName: "phone.circle.fill")
.font(.system(size: 60))
.foregroundColor(.blue)

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.

medium

Use .foregroundStyle instead of the deprecated .foregroundColor modifier.

Suggested change
Image(systemName: "phone.circle.fill")
.font(.system(size: 60))
.foregroundColor(.blue)
Image(systemName: "phone.circle.fill")
.font(.system(size: 60))
.foregroundStyle(.blue)

Comment on lines +40 to +42
Text(authService.string.forSecurityVerifyPhoneMessage)
.font(.body)
.foregroundColor(.secondary)

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.

medium

Use .foregroundStyle instead of the deprecated .foregroundColor modifier.

Suggested change
Text(authService.string.forSecurityVerifyPhoneMessage)
.font(.body)
.foregroundColor(.secondary)
Text(authService.string.forSecurityVerifyPhoneMessage)
.font(.body)
.foregroundStyle(.secondary)

Comment on lines +110 to +135
private func verify() {
guard isValid, !isLoading else { return }
isLoading = true
errorMessage = nil
Task {
defer { isLoading = false }
do {
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
try await authService.reauthenticate(with: credential)
coordinator.reauthCompleted()
} catch let AuthServiceError.multiFactorReauthenticationRequired(mfaRequired) {
self.mfaRequired = mfaRequired
} catch {
errorMessage = authService.string.localizedErrorMessage(for: error)
if let reportError {
reportError(error)
} else {
self.error = AlertError(
title: "Error",
message: error.localizedDescription,
underlyingError: error
)
}
}
}
}

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.

medium

To reduce code duplication and maintain consistency with PhoneReauthScreen and EmailLinkReauthScreen, extract the error reporting logic into a private report(_:) helper method.

  private func verify() {
    guard isValid, !isLoading else { return }
    isLoading = true
    errorMessage = nil
    Task {
      defer { isLoading = false }
      do {
        let credential = EmailAuthProvider.credential(withEmail: email, password: password)
        try await authService.reauthenticate(with: credential)
        coordinator.reauthCompleted()
      } catch let AuthServiceError.multiFactorReauthenticationRequired(mfaRequired) {
        self.mfaRequired = mfaRequired
      } catch {
        report(error)
      }
    }
  }

  private func report(_ error: Error) {
    errorMessage = authService.string.localizedErrorMessage(for: error)
    if let reportError {
      reportError(error)
    } else {
      self.error = AlertError(
        title: "Error",
        message: error.localizedDescription,
        underlyingError: error
      )
    }
  }

@demolaf
demolaf removed this pull request from stack #1424 October 29, 2026 16:19
@demolaf
demolaf added this pull request to stack #1404 October 29, 2026 16:19
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