Skip to content

feat(auth): legacyFetchSignInWithEmail config option for users still wishing to use auth.fetchSignInWithEmail()#1330

Draft
russellwheatley wants to merge 2 commits intomainfrom
fetchsigninwithemail-feature
Draft

feat(auth): legacyFetchSignInWithEmail config option for users still wishing to use auth.fetchSignInWithEmail()#1330
russellwheatley wants to merge 2 commits intomainfrom
fetchsigninwithemail-feature

Conversation

@russellwheatley
Copy link
Member

Hey there! So you want to contribute to FirebaseUI? Before you file this pull request, follow these steps:

  • Read the contribution guidelines.
  • If this has been discussed in an issue, make sure to mention the issue number here. If not, go file an issue about this to make sure this is a desirable change.
  • If this is a new feature please co-ordinate with someone on FirebaseUI-Android to make sure that we can implement this on both platforms and maintain feature parity.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a legacy sign-in recovery feature to FirebaseUI, allowing users to recover their accounts when they attempt to sign in with an incorrect provider. It adds a new configuration option to enable this feature, modifies error handling to accommodate the new recovery flow, and introduces a new UI component to display the recovery options. Additionally, it includes new tests to ensure the feature functions as expected.

Highlights

  • Legacy Sign-In Recovery: Introduces a new feature to help users recover their accounts when they attempt to sign in with the wrong provider. This is achieved by presenting a recovery modal with a list of available sign-in methods for their email.
  • AuthConfiguration Option: Adds a legacyFetchSignInWithEmail option to AuthConfiguration to enable or disable the legacy sign-in recovery feature.
  • Error Handling: Modifies error handling in various views to accommodate the new legacySignInRecoveryPresented error, preventing the display of error alerts when the recovery modal is presented.
  • UI Enhancements: Adds a new LegacySignInRecoveryView to display the recovery options to the user.
  • Testing: Adds new tests to verify the behavior of the legacy sign-in recovery feature.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@russellwheatley
Copy link
Member Author

/gemini review

Copy link

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

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new legacy sign-in recovery feature for Firebase SwiftUI authentication. This includes adding a legacySignInRecoveryPresented error type, new data structures (LegacySignInOption, LegacySignInRecoveryContext), and methods within AuthService to manage and present recovery options. The AuthConfiguration now includes a legacyFetchSignInWithEmail flag to enable this feature. A new LegacySignInRecoveryView is added to display these options, and AuthPickerView is updated to present this view as a sheet. Error handling in various sign-in flows is adjusted to correctly trigger this recovery mechanism. A critical fix ensures that the legacySignInRecoveryPresented error, which is an internal signal, does not trigger a user-facing error alert.

Comment on lines +123 to +201
func legacySignInRecoveryResolvesEmailLinkProvider() async throws {
let email = createEmail()
try await clearAuthEmulatorState()
try await createEmailLinkOnlyUser(email: email)

let service = try await prepareLegacyRecoveryService(
legacyFetchSignInWithEmail: true,
includeEmailLinkProvider: true
)

do {
try await service.signIn(email: email, password: kPassword)
Issue.record("Expected email/password sign-in to fail for an email-link account")
} catch {
if case .legacySignInRecoveryPresented = error as? AuthServiceError {
// Expected path.
} else {
Issue.record("Expected legacy recovery error, got: \(error)")
}
}

let recovery = service.legacySignInRecovery
#expect(recovery?.email == email)
#expect(recovery?.options.contains(where: { $0.id == "emailLink" }) == true)
}

@Test
@MainActor
func legacySignInRecoveryFallsBackWhenProviderNotEnabled() async throws {
let email = createEmail()
try await clearAuthEmulatorState()
try await createEmailLinkOnlyUser(email: email)

let service = try await prepareLegacyRecoveryService(
legacyFetchSignInWithEmail: true,
includeEmailLinkProvider: false
)

do {
try await service.signIn(email: email, password: kPassword)
Issue.record("Expected email/password sign-in to fail for an email-link account")
} catch {
#expect((error as? AuthServiceError) == nil || {
if case .legacySignInRecoveryPresented = error as? AuthServiceError {
return false
}
return true
}())
}

#expect(service.legacySignInRecovery == nil)
}

@Test
@MainActor
func legacySignInRecoveryDisabledPreservesExistingFailure() async throws {
let email = createEmail()
try await clearAuthEmulatorState()
try await createEmailLinkOnlyUser(email: email)

let service = try await prepareLegacyRecoveryService(
legacyFetchSignInWithEmail: false,
includeEmailLinkProvider: true
)

do {
try await service.signIn(email: email, password: kPassword)
Issue.record("Expected email/password sign-in to fail for an email-link account")
} catch {
#expect((error as? AuthServiceError) == nil || {
if case .legacySignInRecoveryPresented = error as? AuthServiceError {
return false
}
return true
}())
}

#expect(service.legacySignInRecovery == nil)
}

Choose a reason for hiding this comment

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

high

The new unit tests (legacySignInRecoveryResolvesEmailLinkProvider, legacySignInRecoveryFallsBackWhenProviderNotEnabled, legacySignInRecoveryDisabledPreservesExistingFailure) provide good coverage for the core logic and edge cases of the legacy sign-in recovery feature, ensuring its reliability.

  @Test
  @MainActor
  func legacySignInRecoveryResolvesEmailLinkProvider() async throws {
    let email = createEmail()
    try await clearAuthEmulatorState()
    try await createEmailLinkOnlyUser(email: email)

    let service = try await prepareLegacyRecoveryService(
      legacyFetchSignInWithEmail: true,
      includeEmailLinkProvider: true
    )

    do {
      try await service.signIn(email: email, password: kPassword)
      Issue.record("Expected email/password sign-in to fail for an email-link account")
    } catch {
      if case .legacySignInRecoveryPresented = error as? AuthServiceError {
        // Expected path.
      } else {
        Issue.record("Expected legacy recovery error, got: \(error)")
      }
    }

    let recovery = service.legacySignInRecovery
    #expect(recovery?.email == email)
    #expect(recovery?.options.contains(where: { $0.id == "emailLink" }) == true)
  }

  @Test
  @MainActor
  func legacySignInRecoveryFallsBackWhenProviderNotEnabled() async throws {
    let email = createEmail()
    try await clearAuthEmulatorState()
    try await createEmailLinkOnlyUser(email: email)

    let service = try await prepareLegacyRecoveryService(
      legacyFetchSignInWithEmail: true,
      includeEmailLinkProvider: false
    )

    do {
      try await service.signIn(email: email, password: kPassword)
      Issue.record("Expected email/password sign-in to fail for an email-link account")
    } catch {
      #expect((error as? AuthServiceError) == nil || {
        if case .legacySignInRecoveryPresented = error as? AuthServiceError {
          return false
        }
        return true
      }())
    }

    #expect(service.legacySignInRecovery == nil)
  }

  @Test
  @MainActor
  func legacySignInRecoveryDisabledPreservesExistingFailure() async throws {
    let email = createEmail()
    try await clearAuthEmulatorState()
    try await createEmailLinkOnlyUser(email: email)

    let service = try await prepareLegacyRecoveryService(
      legacyFetchSignInWithEmail: false,
      includeEmailLinkProvider: true
    )

    do {
      try await service.signIn(email: email, password: kPassword)
      Issue.record("Expected email/password sign-in to fail for an email-link account")
    } catch {
      #expect((error as? AuthServiceError) == nil || {
        if case .legacySignInRecoveryPresented = error as? AuthServiceError {
          return false
        }
        return true
      }())
    }

    #expect(service.legacySignInRecovery == nil)
  }

Comment on lines +63 to +90
public struct LegacySignInOption: Identifiable, Equatable {
public let id: String
public let displayName: String

public init(id: String, displayName: String) {
self.id = id
self.displayName = displayName
}
}

public struct LegacySignInRecoveryContext: Identifiable, Equatable {
public let id = UUID()
public let email: String
public let options: [LegacySignInOption]
public let unavailableProviders: [String]

public init(email: String,
options: [LegacySignInOption],
unavailableProviders: [String] = []) {
self.email = email
self.options = options
self.unavailableProviders = unavailableProviders
}

public static func == (lhs: LegacySignInRecoveryContext,
rhs: LegacySignInRecoveryContext) -> Bool {
lhs.id == rhs.id
}

Choose a reason for hiding this comment

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

medium

The introduction of LegacySignInOption and LegacySignInRecoveryContext provides clear and structured data models for managing the new sign-in recovery flow. Conforming to Identifiable and Equatable is good practice for SwiftUI integration.

public struct LegacySignInOption: Identifiable, Equatable {
  public let id: String
  public let displayName: String

  public init(id: String, displayName: String) {
    self.id = id
    self.displayName = displayName
  }
}

public struct LegacySignInRecoveryContext: Identifiable, Equatable {
  public let id = UUID()
  public let email: String
  public let options: [LegacySignInOption]
  public let unavailableProviders: [String]

  public init(email: String,
              options: [LegacySignInOption],
              unavailableProviders: [String] = []) {
    self.email = email
    self.options = options
    self.unavailableProviders = unavailableProviders
  }

  public static func == (lhs: LegacySignInRecoveryContext,
                         rhs: LegacySignInRecoveryContext) -> Bool {
    lhs.id == rhs.id
  }
}

@russellwheatley russellwheatley force-pushed the fetchsigninwithemail-feature branch from bd1e9fd to 179f5ba Compare March 23, 2026 16:22
@russellwheatley russellwheatley changed the title Fetchsigninwithemail feature feat(auth): legacyFetchSignInWithEmail config option for users still wishing to use auth.fetchSignInWithEmail() Mar 23, 2026
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