Skip to content

Commit bbce389

Browse files
refactor: google provider
1 parent 8c15371 commit bbce389

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/AccountService+Google.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ extension GoogleOperationReauthentication {
4141
}
4242

4343
do {
44-
let credential = try await googleProvider
45-
.signInWithGoogle(clientID: googleProvider.clientID)
44+
let credential = try await googleProvider.createAuthCredential()
4645
try await user.reauthenticate(with: credential)
4746

4847
return .firebase("")

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/GoogleProviderAuthUI.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class GoogleProviderAuthUI: AuthProviderSwift, AuthProviderUI, DeleteUser
4444
}
4545

4646
@MainActor public func authButton() -> AnyView {
47-
// Moved to SignInWithGoogleButton so we could sign in via AuthService
4847
AnyView(SignInWithGoogleButton())
4948
}
5049

@@ -54,10 +53,6 @@ public class GoogleProviderAuthUI: AuthProviderSwift, AuthProviderUI, DeleteUser
5453
}
5554

5655
@MainActor public func createAuthCredential() async throws -> AuthCredential {
57-
return try await signInWithGoogle(clientID: clientID)
58-
}
59-
60-
@MainActor public func signInWithGoogle(clientID: String) async throws -> AuthCredential {
6156
guard let presentingViewController = await (UIApplication.shared.connectedScenes
6257
.first as? UIWindowScene)?.windows.first?.rootViewController else {
6358
throw GoogleProviderError
@@ -66,7 +61,7 @@ public class GoogleProviderAuthUI: AuthProviderSwift, AuthProviderUI, DeleteUser
6661
)
6762
}
6863

69-
let config = GIDConfiguration(clientID: clientID)
64+
let config = GIDConfiguration(clientID: self.clientID)
7065
GIDSignIn.sharedInstance.configuration = config
7166

7267
return try await withCheckedThrowingContinuation { continuation in

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Views/SignInWithGoogleButton.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import SwiftUI
2626
@MainActor
2727
public struct SignInWithGoogleButton {
2828
@Environment(AuthService.self) private var authService
29+
private let googleProvider = GoogleProviderAuthUI()
2930

3031
let customViewModel = GoogleSignInButtonViewModel(
3132
scheme: .light,
@@ -38,11 +39,7 @@ extension SignInWithGoogleButton: View {
3839
public var body: some View {
3940
GoogleSignInButton(viewModel: customViewModel) {
4041
Task {
41-
guard let clientID = authService.auth.app?.options.clientID else {
42-
return
43-
}
44-
let provider = GoogleProviderAuthUI(clientID: clientID)
45-
try await authService.signInWithProvider(provider)
42+
try await authService.signInWithProvider(googleProvider)
4643
}
4744
}
4845
}

0 commit comments

Comments
 (0)