1515import FirebaseAuth
1616import 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
1978public 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
0 commit comments