Skip to content

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

Open
demolaf wants to merge 1 commit into
auth/picker-slotsfrom
auth/method-picker-layout
Open

demolaf wants to merge 1 commit into
auth/picker-slotsfrom
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

…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 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 on lines +90 to +94
do {
result = try await .success(authService.triggerSignIn(for: provider))
} catch {
result = .failure(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

Using try await .success(...) is unidiomatic and can be confusing to read because .success is an enum case constructor, not an asynchronous or throwing function. The try await keyword actually applies to the nested authService.triggerSignIn(for: provider) call.

It is much cleaner and more readable to await the result first, and then wrap it in the Result.success case.

      do {
        let outcome = try await authService.triggerSignIn(for: provider)
        result = .success(outcome)
      } catch {
        result = .failure(error)
      }

Comment on lines +69 to 71
VStack {
authMethodPicker(pickerState)
}

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

Wrapping authMethodPicker(pickerState) in a VStack is redundant since it is the only child element and has no layout modifiers or spacing applied to the VStack itself. You can call authMethodPicker(pickerState) directly to avoid unnecessary nesting in the view hierarchy.

        authMethodPicker(pickerState)

Comment on lines 165 to +169
VStack {
authService.renderButtons()
}
// 72% of the container width, matching a 14% inset on each side.
.containerRelativeFrame(.horizontal) { length, _ in length * 0.72 }

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

authService.renderButtons() already returns a VStack internally (wrapped in AnyView). Wrapping it in another VStack here is redundant. You can apply the .containerRelativeFrame modifier directly to authService.renderButtons().

Suggested change
VStack {
authService.renderButtons()
}
// 72% of the container width, matching a 14% inset on each side.
.containerRelativeFrame(.horizontal) { length, _ in length * 0.72 }
authService.renderButtons()
// 72% of the container width, matching a 14% inset on each side.
.containerRelativeFrame(.horizontal) { length, _ in length * 0.72 }

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