Skip to content

feat(auth): support custom method picker layouts in DefaultAuthPickerContent - #1411

Merged
demolaf merged 9 commits into
mainfrom
auth/method-picker-layout
Oct 30, 2026
Merged

demolaf merged 9 commits into
mainfrom
auth/method-picker-layout

Conversation

@demolaf

@demolaf demolaf commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Adds DefaultAuthPickerContent(authMethodPicker:) so apps can lay out the provider buttons themselves, with the same MFA, account-conflict and error handling as the default buttons. Stacked on #1403.

Changes

  • The layout closure receives an AuthMethodPickerState: providers, select(_:), isEmailLinkEnabled and selectEmailLink(), so a custom layout can't silently drop email-link sign-in. Its public init lets apps preview layouts with stub actions.
  • AuthService gains registeredProviders and triggerSignIn(for:). The new opt-in AuthProviderAction covers providers with no credential and takes precedence when adopted; PhoneAuthProviderAuthUI adopts it.
  • select(_:) reports an error for a provider that is neither credential-based nor AuthProviderAction, instead of doing nothing.
  • The 14% horizontal inset moves into DefaultAuthMethodPicker, so custom layouts aren't padded. The default screen is pixel-identical to main.

API Usage

AuthPickerView { authenticatedApp }
  .pickerContent {
    DefaultAuthPickerContent { state in
      ForEach(state.providers, id: \.id) { provider in
        Button(provider.displayName) { state.select(provider) }
      }
      if state.isEmailLinkEnabled {
        Button("Email link", action: state.selectEmailLink)
      }
    }
  }

Maintainer note: Fixes internal CPRN-517

@demolaf
demolaf added this pull request to stack #1404 October 20, 2026 11:30
@demolaf demolaf changed the title auth/method picker layout feat(auth): support custom method picker layouts in DefaultAuthPickerContent Oct 20, 2026

@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 introduces the AuthProviderAction protocol and updates AuthService to support programmatic sign-in for custom providers. It also refactors DefaultAuthPickerContent to allow custom layouts for provider buttons via AuthMethodPickerState and adds comprehensive unit tests. The review feedback suggests improving code readability and efficiency by avoiding unidiomatic try await .success(...) syntax and removing redundant VStack wrappers in SwiftUI views.

Comment thread FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/DefaultAuthPickerContent.swift Outdated
@demolaf
demolaf marked this pull request as ready for review October 20, 2026 13:54
@demolaf
demolaf force-pushed the auth/method-picker-layout branch from 2f0737d to c72d599 Compare October 22, 2026 11:45
@demolaf
demolaf force-pushed the auth/method-picker-layout branch 2 times, most recently from c19f385 to 47cc305 Compare October 27, 2026 12:17
Base automatically changed from auth/picker-slots to main October 29, 2026 09:20
…Content

Add DefaultAuthPickerContent(authMethodPicker:), which hands the layout an AuthMethodPickerState with the registered providers, a select action that routes MFA, account conflicts and errors like the default buttons, and the email-link state and action.

Add AuthService.registeredProviders and triggerSignIn(for:), plus the opt-in AuthProviderAction protocol for providers whose sign-in yields no credential; PhoneAuthProviderAuthUI adopts it. Providers that support neither path report an error instead of doing nothing.

Move the 14% horizontal inset into DefaultAuthMethodPicker so custom layouts are not padded.
@demolaf
demolaf force-pushed the auth/method-picker-layout branch from 47cc305 to 2b58f2d Compare October 29, 2026 09:20
Comment thread FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift Outdated
…Action

An action provider that signs in directly can now hand back .mfaRequired, so a custom method picker routes it to the standard MFA handler. Phone still returns nil after pushing its screen.
MFA can only be resolved for an outcome from AuthService.signIn(credentials:), so the protocol doc says so and the example stores its AuthService and runs on the main actor. Adds tests that an action's MFA outcome and account conflict reach their handlers.
@demolaf
demolaf merged commit 11c5a81 into main Oct 30, 2026
24 of 25 checks passed
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.

2 participants