Skip to content

Commit 0cb634d

Browse files
fix: user requests sms in PhoneReauthView
1 parent 0d90729 commit 0cb634d

3 files changed

Lines changed: 56 additions & 18 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/ReauthenticationCoordinator.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class ReauthenticationCoordinator {
4848
public var isReauthenticating = false
4949
public var reauthContext: ReauthContext?
5050
public var showingPhoneReauth = false
51+
public var showingPhoneReauthAlert = false
5152

5253
private var continuation: CheckedContinuation<Void, Error>?
5354

@@ -59,15 +60,21 @@ public final class ReauthenticationCoordinator {
5960
self.continuation = continuation
6061
self.reauthContext = context
6162

62-
// Show different UI based on provider
63+
// Show alert first for all providers (including phone)
6364
if context.providerId == PhoneAuthProviderID {
64-
self.showingPhoneReauth = true
65+
self.showingPhoneReauthAlert = true
6566
} else {
6667
self.isReauthenticating = true
6768
}
6869
}
6970
}
7071

72+
/// Called when user confirms phone reauth alert
73+
public func confirmPhoneReauth() {
74+
showingPhoneReauthAlert = false
75+
showingPhoneReauth = true
76+
}
77+
7178
/// Called when reauthentication completes successfully
7279
public func reauthCompleted() {
7380
continuation?.resume()
@@ -84,6 +91,7 @@ public final class ReauthenticationCoordinator {
8491
continuation = nil
8592
isReauthenticating = false
8693
showingPhoneReauth = false
94+
showingPhoneReauthAlert = false
8795
reauthContext = nil
8896
}
8997
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PhoneReauthView.swift

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,40 @@ extension PhoneReauthView: View {
102102
.font(.body)
103103
.foregroundColor(.secondary)
104104
.multilineTextAlignment(.center)
105-
106-
Text(phoneNumber)
107-
.font(.headline)
108-
.foregroundColor(.primary)
109105
}
110106
.padding()
111107

112108
if verificationID == nil {
113-
// Send SMS button
114-
Button("Send Verification Code") {
115-
sendSMS()
109+
// Initial state - sending SMS
110+
VStack(spacing: 16) {
111+
if isLoading {
112+
ProgressView()
113+
.scaleEffect(1.5)
114+
.padding()
115+
116+
Text("Sending verification code...")
117+
.font(.body)
118+
.foregroundColor(.secondary)
119+
120+
Text(phoneNumber)
121+
.font(.headline)
122+
} else {
123+
Text("We'll send a verification code to:")
124+
.font(.body)
125+
.foregroundColor(.secondary)
126+
127+
Text(phoneNumber)
128+
.font(.headline)
129+
.padding(.bottom, 8)
130+
131+
Button("Send Verification Code") {
132+
sendSMS()
133+
}
134+
.buttonStyle(.borderedProminent)
135+
.accessibilityIdentifier("send-verification-code-button")
136+
}
116137
}
117-
.buttonStyle(.borderedProminent)
118-
.disabled(isLoading)
119138
.padding()
120-
.accessibilityIdentifier("send-verification-code-button")
121139
} else {
122140
// Enter verification code
123141
AuthTextField(
@@ -162,10 +180,6 @@ extension PhoneReauthView: View {
162180
}
163181
}
164182
.errorAlert(error: $error, okButtonLabel: authService.string.okButtonLabel)
165-
.onAppear {
166-
// Auto-send SMS on appear for better UX
167-
sendSMS()
168-
}
169183
}
170184
}
171185

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/ReauthenticationModifier.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ReauthenticationModifier: ViewModifier {
2222

2323
func body(content: Content) -> some View {
2424
content
25-
// Alert asking user to reauthenticate
25+
// Alert for non-phone providers
2626
.alert(
2727
"Authentication Required",
2828
isPresented: $coordinator.isReauthenticating
@@ -38,7 +38,23 @@ struct ReauthenticationModifier: ViewModifier {
3838
Text(context.displayMessage)
3939
}
4040
}
41-
// Sheet for phone reauthentication
41+
// Alert for phone provider
42+
.alert(
43+
"Phone Verification Required",
44+
isPresented: $coordinator.showingPhoneReauthAlert
45+
) {
46+
Button("Proceed") {
47+
coordinator.confirmPhoneReauth()
48+
}
49+
Button("Cancel", role: .cancel) {
50+
coordinator.reauthCancelled()
51+
}
52+
} message: {
53+
if let phoneNumber = coordinator.reauthContext?.phoneNumber {
54+
Text("For security, we need to verify your phone number: \(phoneNumber)")
55+
}
56+
}
57+
// Sheet for phone reauthentication (shown after alert confirmation)
4258
.sheet(isPresented: $coordinator.showingPhoneReauth) {
4359
if let phoneNumber = coordinator.reauthContext?.phoneNumber {
4460
PhoneReauthView(

0 commit comments

Comments
 (0)