Skip to content

Commit 1ffa862

Browse files
chore: implement displayName for friendly provider messages
1 parent 9ef04f9 commit 1ffa862

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

FirebaseSwiftUI/FirebaseAppleSwiftUI/Sources/Services/AppleProviderAuthUI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public class AppleProviderAuthUI: AuthProviderUI {
143143
private let typedProvider: AppleProviderSwift
144144
public var provider: AuthProviderSwift { typedProvider }
145145
public let id: String = "apple.com"
146+
public let displayName: String = "Apple"
146147

147148
public init(provider: AppleProviderSwift) {
148149
typedProvider = provider

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public protocol CredentialAuthProviderSwift: AuthProviderSwift {
2828

2929
public protocol AuthProviderUI {
3030
var id: String { get }
31+
var displayName: String { get }
3132
@MainActor func authButton() -> AnyView
3233
var provider: AuthProviderSwift { get }
3334
}
@@ -776,9 +777,19 @@ public extension AuthService {
776777
/// - Throws: Appropriate `AuthServiceError` based on the provider type
777778
private func requireReauthentication() async throws -> Never {
778779
let providerId = try await getCurrentSignInProvider()
780+
781+
// Try to find display name from registered provider
782+
let providerDisplayName: String
783+
if let registeredProvider = providers.first(where: { $0.id == providerId }) {
784+
providerDisplayName = registeredProvider.displayName
785+
} else {
786+
// Fallback for built-in providers (email/password) that don't have AuthProviderUI
787+
providerDisplayName = getProviderDisplayName(providerId)
788+
}
789+
779790
let context = ReauthContext(
780791
providerId: providerId,
781-
providerName: getProviderDisplayName(providerId),
792+
providerName: providerDisplayName,
782793
phoneNumber: currentUser?.phoneNumber,
783794
email: currentUser?.email
784795
)
@@ -824,7 +835,8 @@ public extension AuthService {
824835
return providerId
825836
}
826837

827-
/// Get a user-friendly display name for a provider ID
838+
/// Get a user-friendly display name for built-in providers without AuthProviderUI
839+
/// (email/password). Other providers should be registered and provide their own display names.
828840
/// - Parameter providerId: The provider ID from Firebase Auth
829841
/// - Returns: A user-friendly name for the provider
830842
private func getProviderDisplayName(_ providerId: String) -> String {
@@ -833,15 +845,8 @@ public extension AuthService {
833845
return "Email"
834846
case PhoneAuthProviderID:
835847
return "Phone"
836-
case "google.com":
837-
return "Google"
838-
case "apple.com":
839-
return "Apple"
840-
case "facebook.com":
841-
return "Facebook"
842-
case "twitter.com":
843-
return "Twitter"
844848
default:
849+
// Shouldn't reach here if provider is registered
845850
return providerId
846851
}
847852
}

FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Services/FacebookProviderAuthUI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class FacebookProviderAuthUI: AuthProviderUI {
122122
private let typedProvider: FacebookProviderSwift
123123
public var provider: AuthProviderSwift { typedProvider }
124124
public let id: String = "facebook.com"
125+
public let displayName: String = "Facebook"
125126

126127
public init(provider: FacebookProviderSwift) {
127128
typedProvider = provider

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/GoogleProviderAuthUI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class GoogleProviderAuthUI: AuthProviderUI {
7474
private let typedProvider: GoogleProviderSwift
7575
public var provider: AuthProviderSwift { typedProvider }
7676
public let id: String = "google.com"
77+
public let displayName: String = "Google"
7778

7879
public init(provider: GoogleProviderSwift) {
7980
typedProvider = provider

FirebaseSwiftUI/FirebaseOAuthSwiftUI/Sources/Services/OAuthProviderSwift+Presets.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public extension OAuthProviderSwift {
2525
return OAuthProviderSwift(
2626
providerId: "github.com",
2727
scopes: scopes,
28-
displayName: "Sign in with GitHub",
28+
buttonLabel: "Sign in with GitHub",
29+
displayName: "GitHub",
2930
buttonIcon: ProviderStyle.github.icon!,
3031
buttonBackgroundColor: ProviderStyle.github.backgroundColor,
3132
buttonForegroundColor: ProviderStyle.github.contentColor
@@ -41,7 +42,8 @@ public extension OAuthProviderSwift {
4142
providerId: "microsoft.com",
4243
scopes: scopes,
4344
customParameters: ["prompt": "consent"],
44-
displayName: "Sign in with Microsoft",
45+
buttonLabel: "Sign in with Microsoft",
46+
displayName: "Microsoft",
4547
buttonIcon: ProviderStyle.microsoft.icon!,
4648
buttonBackgroundColor: ProviderStyle.microsoft.backgroundColor,
4749
buttonForegroundColor: ProviderStyle.microsoft.contentColor
@@ -57,7 +59,8 @@ public extension OAuthProviderSwift {
5759
providerId: "yahoo.com",
5860
scopes: scopes,
5961
customParameters: ["prompt": "consent"],
60-
displayName: "Sign in with Yahoo",
62+
buttonLabel: "Sign in with Yahoo",
63+
displayName: "Yahoo",
6164
buttonIcon: ProviderStyle.yahoo.icon!,
6265
buttonBackgroundColor: ProviderStyle.yahoo.backgroundColor,
6366
buttonForegroundColor: ProviderStyle.yahoo.contentColor

FirebaseSwiftUI/FirebaseOAuthSwiftUI/Sources/Services/OAuthProviderSwift.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class OAuthProviderSwift: CredentialAuthProviderSwift {
2323
public let scopes: [String]
2424
public let customParameters: [String: String]
2525
// Button appearance
26+
public let buttonLabel: String
2627
public let displayName: String
2728
public let buttonIcon: Image
2829
public let buttonBackgroundColor: Color
@@ -32,20 +33,23 @@ public class OAuthProviderSwift: CredentialAuthProviderSwift {
3233
/// - providerId: The OAuth provider ID (e.g., "github.com", "microsoft.com")
3334
/// - scopes: OAuth scopes to request
3435
/// - customParameters: Additional OAuth parameters
35-
/// - displayName: Button label (e.g., "Sign in with GitHub")
36+
/// - buttonLabel: Full button label (e.g., "Sign in with GitHub")
37+
/// - displayName: Short provider name for messages (e.g., "GitHub")
3638
/// - buttonIcon: Button icon image
3739
/// - buttonBackgroundColor: Button background color
3840
/// - buttonForegroundColor: Button text/icon color
3941
public init(providerId: String,
4042
scopes: [String] = [],
4143
customParameters: [String: String] = [:],
44+
buttonLabel: String,
4245
displayName: String,
4346
buttonIcon: Image,
4447
buttonBackgroundColor: Color = .black,
4548
buttonForegroundColor: Color = .white) {
4649
self.providerId = providerId
4750
self.scopes = scopes
4851
self.customParameters = customParameters
52+
self.buttonLabel = buttonLabel
4953
self.displayName = displayName
5054
self.buttonIcon = buttonIcon
5155
self.buttonBackgroundColor = buttonBackgroundColor
@@ -57,13 +61,15 @@ public class OAuthProviderSwift: CredentialAuthProviderSwift {
5761
/// - providerId: The OAuth provider ID (e.g., "github.com", "microsoft.com")
5862
/// - scopes: OAuth scopes to request
5963
/// - customParameters: Additional OAuth parameters
60-
/// - displayName: Button label (e.g., "Sign in with GitHub")
64+
/// - buttonLabel: Full button label (e.g., "Sign in with GitHub")
65+
/// - displayName: Short provider name for messages (e.g., "GitHub")
6166
/// - iconSystemName: SF Symbol name
6267
/// - buttonBackgroundColor: Button background color
6368
/// - buttonForegroundColor: Button text/icon color
6469
public convenience init(providerId: String,
6570
scopes: [String] = [],
6671
customParameters: [String: String] = [:],
72+
buttonLabel: String,
6773
displayName: String,
6874
iconSystemName: String,
6975
buttonBackgroundColor: Color = .black,
@@ -72,6 +78,7 @@ public class OAuthProviderSwift: CredentialAuthProviderSwift {
7278
providerId: providerId,
7379
scopes: scopes,
7480
customParameters: customParameters,
81+
buttonLabel: buttonLabel,
7582
displayName: displayName,
7683
buttonIcon: Image(systemName: iconSystemName),
7784
buttonBackgroundColor: buttonBackgroundColor,
@@ -127,6 +134,10 @@ public class OAuthProviderAuthUI: AuthProviderUI {
127134
return typedProvider.providerId
128135
}
129136

137+
public var displayName: String {
138+
return typedProvider.displayName
139+
}
140+
130141
@MainActor public func authButton() -> AnyView {
131142
AnyView(GenericOAuthButton(provider: typedProvider))
132143
}

FirebaseSwiftUI/FirebaseOAuthSwiftUI/Sources/Views/GenericOAuthButton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension GenericOAuthButton: View {
4242

4343
return AnyView(
4444
AuthProviderButton(
45-
label: provider.displayName,
45+
label: provider.buttonLabel,
4646
style: resolvedStyle,
4747
accessibilityId: "sign-in-with-\(provider.providerId)-button"
4848
) {

FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources/Services/PhoneAuthProviderAuthUI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PhoneAuthProviderAuthUI: AuthProviderUI {
2424
private let typedProvider: PhoneProviderSwift
2525
public var provider: AuthProviderSwift { typedProvider }
2626
public let id: String = "phone"
27+
public let displayName: String = "Phone"
2728

2829
// Callback for when the phone auth button is tapped
2930
private let onTap: () -> Void

FirebaseSwiftUI/FirebaseTwitterSwiftUI/Sources/Services/TwitterProviderAuthUI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class TwitterProviderAuthUI: AuthProviderUI {
4848
private let typedProvider: TwitterProviderSwift
4949
public var provider: AuthProviderSwift { typedProvider }
5050
public let id: String = "twitter.com"
51+
public let displayName: String = "Twitter"
5152

5253
public init(provider: TwitterProviderSwift) {
5354
typedProvider = provider

0 commit comments

Comments
 (0)