Repository navigation
Conversation
…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.
There was a problem hiding this comment.
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.
| do { | ||
| result = try await .success(authService.triggerSignIn(for: provider)) | ||
| } catch { | ||
| result = .failure(error) | ||
| } |
There was a problem hiding this comment.
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)
}| VStack { | ||
| authMethodPicker(pickerState) | ||
| } |
There was a problem hiding this comment.
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)| VStack { | ||
| authService.renderButtons() | ||
| } | ||
| // 72% of the container width, matching a 14% inset on each side. | ||
| .containerRelativeFrame(.horizontal) { length, _ in length * 0.72 } |
There was a problem hiding this comment.
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().
| 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 } |
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
AuthMethodPickerState:providers,select(_:),isEmailLinkEnabledandselectEmailLink(), so a custom layout can't silently drop email-link sign-in. Its public init lets apps preview layouts with stub actions.AuthServicegainsregisteredProvidersandtriggerSignIn(for:). The new opt-inAuthProviderActioncovers providers with no credential and takes precedence when adopted;PhoneAuthProviderAuthUIadopts it.select(_:)reports an error for a provider that is neither credential-based norAuthProviderAction, instead of doing nothing.DefaultAuthMethodPicker, so custom layouts aren't padded. The default screen is pixel-identical tomain.API Usage
Maintainer note: Fixes internal CPRN-517