Skip to content

Commit fec75eb

Browse files
fix: facebook error modal
1 parent 8c3ce69 commit fec75eb

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Views/SignInWithFacebookButton.swift

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import SwiftUI
2424
public struct SignInWithFacebookButton {
2525
@Environment(AuthService.self) private var authService
2626
let facebookProvider: AuthProviderSwift
27-
@State private var currentError: AlertError?
2827
@State private var showCanceledAlert = false
2928
@State private var limitedLogin = true
3029
@State private var showUserTrackingAlert = false
@@ -64,67 +63,69 @@ public struct SignInWithFacebookButton {
6463

6564
extension SignInWithFacebookButton: View {
6665
public var body: some View {
67-
Button(action: {
68-
Task {
69-
do {
70-
try await authService.signIn(facebookProvider)
71-
} catch {
72-
switch error {
73-
case FacebookProviderError.signInCancelled:
74-
showCanceledAlert = true
75-
default:
76-
currentError = AlertError(message: authService.string.localizedErrorMessage(for: error))
66+
VStack {
67+
Button(action: {
68+
Task {
69+
do {
70+
try await authService.signIn(facebookProvider)
71+
} catch {
72+
switch error {
73+
case FacebookProviderError.signInCancelled:
74+
showCanceledAlert = true
75+
default:
76+
// Error already handled by AuthService
77+
break
78+
}
7779
}
7880
}
81+
}) {
82+
HStack {
83+
Image(systemName: "f.circle.fill")
84+
.font(.title2)
85+
.foregroundColor(.white)
86+
Text(authService.string.facebookLoginButtonLabel)
87+
.fontWeight(.semibold)
88+
.foregroundColor(.white)
89+
}
90+
.frame(maxWidth: .infinity, alignment: .leading)
91+
.padding()
92+
.frame(maxWidth: .infinity)
93+
.background(Color.blue)
94+
.cornerRadius(8)
7995
}
80-
}) {
96+
.accessibilityIdentifier("sign-in-with-facebook-button")
97+
8198
HStack {
82-
Image(systemName: "f.circle.fill")
83-
.font(.title2)
84-
.foregroundColor(.white)
85-
Text(authService.string.facebookLoginButtonLabel)
86-
.fontWeight(.semibold)
87-
.foregroundColor(.white)
99+
Text(authService.string.authorizeUserTrackingLabel)
100+
.font(.footnote)
101+
.foregroundColor(.blue)
102+
.underline()
103+
.onTapGesture {
104+
requestTrackingPermission()
105+
}
106+
Toggle(isOn: limitedLoginBinding) {
107+
HStack {
108+
Spacer() // This will push the text to the left of the toggle
109+
Text(authService.string.facebookLimitedLoginLabel)
110+
.foregroundColor(.blue)
111+
}
112+
}
113+
.toggleStyle(SwitchToggleStyle(tint: .green))
88114
}
89-
.frame(maxWidth: .infinity, alignment: .leading)
90-
.padding()
91-
.frame(maxWidth: .infinity)
92-
.background(Color.blue)
93-
.cornerRadius(8)
94115
}
95-
.accessibilityIdentifier("sign-in-with-facebook-button")
96116
.alert(isPresented: $showCanceledAlert) {
97117
Alert(
98118
title: Text(authService.string.facebookLoginCancelledLabel),
99119
dismissButton: .default(Text(authService.string.okButtonLabel))
100120
)
101121
}
102-
103-
HStack {
104-
Text(authService.string.authorizeUserTrackingLabel)
105-
.font(.footnote)
106-
.foregroundColor(.blue)
107-
.underline()
108-
.onTapGesture {
109-
requestTrackingPermission()
110-
}
111-
Toggle(isOn: limitedLoginBinding) {
112-
HStack {
113-
Spacer() // This will push the text to the left of the toggle
114-
Text(authService.string.facebookLimitedLoginLabel)
115-
.foregroundColor(.blue)
116-
}
117-
}
118-
.toggleStyle(SwitchToggleStyle(tint: .green))
119-
.alert(isPresented: $showUserTrackingAlert) {
120-
Alert(
121-
title: Text(authService.string.authorizeUserTrackingLabel),
122-
message: Text(authService.string.facebookAuthorizeUserTrackingMessage),
123-
dismissButton: .default(Text(authService.string.okButtonLabel))
124-
)
125-
}
122+
.alert(isPresented: $showUserTrackingAlert) {
123+
Alert(
124+
title: Text(authService.string.authorizeUserTrackingLabel),
125+
message: Text(authService.string.facebookAuthorizeUserTrackingMessage),
126+
dismissButton: .default(Text(authService.string.okButtonLabel))
127+
)
126128
}
127-
.errorAlert(error: $currentError, okButtonLabel: authService.string.okButtonLabel)
128129
}
129130
}
130131

0 commit comments

Comments
 (0)