Skip to content

Commit 9bc3b49

Browse files
Merge pull request #1313 from firebase/reauthentication
2 parents bc65909 + fd7ea41 commit 9bc3b49

File tree

34 files changed

+1309
-552
lines changed

34 files changed

+1309
-552
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/AuthServiceError.swift

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,65 @@
1515
import FirebaseAuth
1616
import SwiftUI
1717

18+
/// Context information for OAuth provider reauthentication (Google, Apple, Facebook, Twitter, etc.)
19+
public struct OAuthReauthContext: Equatable {
20+
public let providerId: String
21+
public let providerName: String
22+
23+
public init(providerId: String, providerName: String) {
24+
self.providerId = providerId
25+
self.providerName = providerName
26+
}
27+
28+
public var displayMessage: String {
29+
"Please sign in with \(providerName) to continue"
30+
}
31+
}
32+
33+
/// Context information for email/password reauthentication
34+
public struct EmailReauthContext: Equatable {
35+
public let email: String
36+
37+
public init(email: String) {
38+
self.email = email
39+
}
40+
41+
public var displayMessage: String {
42+
"Please enter your password to continue"
43+
}
44+
}
45+
46+
/// Context information for phone number reauthentication
47+
public struct PhoneReauthContext: Equatable {
48+
public let phoneNumber: String
49+
50+
public init(phoneNumber: String) {
51+
self.phoneNumber = phoneNumber
52+
}
53+
54+
public var displayMessage: String {
55+
"Please verify your phone number to continue"
56+
}
57+
}
58+
59+
/// Type-safe wrapper for reauthentication contexts
60+
public enum ReauthenticationType: Equatable {
61+
case oauth(OAuthReauthContext)
62+
case email(EmailReauthContext)
63+
case phone(PhoneReauthContext)
64+
65+
public var displayMessage: String {
66+
switch self {
67+
case let .oauth(context):
68+
return context.displayMessage
69+
case let .email(context):
70+
return context.displayMessage
71+
case let .phone(context):
72+
return context.displayMessage
73+
}
74+
}
75+
}
76+
1877
/// Describes the specific type of account conflict that occurred
1978
public enum AccountConflictType: Equatable {
2079
/// Account exists with a different provider (e.g., user signed up with Google, trying to use
@@ -72,7 +131,17 @@ public enum AuthServiceError: LocalizedError {
72131
case invalidEmailLink(String)
73132
case clientIdNotFound(String)
74133
case notConfiguredActionCodeSettings(String)
75-
case reauthenticationRequired(String)
134+
135+
/// OAuth reauthentication required (Google, Apple, Facebook, Twitter, etc.)
136+
/// Can be passed directly to `reauthenticate(context:)` method
137+
case oauthReauthenticationRequired(context: OAuthReauthContext)
138+
139+
/// Email reauthentication required - user must handle password prompt externally
140+
case emailReauthenticationRequired(context: EmailReauthContext)
141+
142+
/// Phone reauthentication required - user must handle SMS verification flow externally
143+
case phoneReauthenticationRequired(context: PhoneReauthContext)
144+
76145
case invalidCredentials(String)
77146
case signInFailed(underlying: Error)
78147
case accountConflict(AccountConflictContext)
@@ -92,8 +161,12 @@ public enum AuthServiceError: LocalizedError {
92161
return description
93162
case let .notConfiguredActionCodeSettings(description):
94163
return description
95-
case let .reauthenticationRequired(description):
96-
return description
164+
case let .oauthReauthenticationRequired(context):
165+
return "Please sign in again with \(context.providerName) to continue"
166+
case .emailReauthenticationRequired:
167+
return "Please enter your password to continue"
168+
case .phoneReauthenticationRequired:
169+
return "Please verify your phone number to continue"
97170
case let .invalidCredentials(description):
98171
return description
99172
// Use when failed to sign-in with Firebase

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AccountService+Email.swift

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)