Skip to content

Commit 5be4e0d

Browse files
committed
move buttons out of viewbuilder
1 parent 0d5d8ba commit 5be4e0d

File tree

8 files changed

+69
-28
lines changed

8 files changed

+69
-28
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
@preconcurrency import FirebaseAuth
22
import SwiftUI
33

4-
public protocol GoogleProviderProtocol {
4+
public protocol ExternalAuthProvider {
5+
@MainActor var authButton: any View { get }
6+
}
7+
8+
public protocol GoogleProviderProtocol: ExternalAuthProvider {
59
func handleUrl(_ url: URL) -> Bool
610
@MainActor func signInWithGoogle(clientID: String) async throws -> AuthCredential
711
}
812

9-
public protocol FacebookProviderProtocol {
13+
public protocol FacebookProviderProtocol: ExternalAuthProvider {
1014
@MainActor func signInWithFacebook(isLimitedLogin: Bool) async throws -> AuthCredential
1115
}
1216

13-
public protocol PhoneAuthProviderProtocol {
17+
public protocol PhoneAuthProviderProtocol: ExternalAuthProvider {
1418
@MainActor func verifyPhoneNumber(phoneNumber: String) async throws -> String
1519
}
1620

@@ -90,10 +94,11 @@ public final class AuthService {
9094
public var authenticationFlow: AuthenticationFlow = .login
9195
public var errorMessage = ""
9296

97+
public var googleProvider: GoogleProviderProtocol?
98+
public var facebookProvider: FacebookProviderProtocol?
99+
public var phoneAuthProvider: PhoneAuthProviderProtocol?
100+
93101
private var listenerManager: AuthListenerManager?
94-
private let googleProvider: GoogleProviderProtocol?
95-
private let facebookProvider: FacebookProviderProtocol?
96-
private let phoneAuthProvider: PhoneAuthProviderProtocol?
97102
private var signedInCredential: AuthCredential?
98103

99104
private var safeGoogleProvider: GoogleProviderProtocol {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Strings/Localizable.xcstrings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
},
163163
"AuthPickerTitle" : {
164164
"comment" : "Title for auth picker screen.",
165+
"extractionState" : "stale",
165166
"localizations" : {
166167
"en" : {
167168
"stringUnit" : {

FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Services/FacebookProviderSwift.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import FacebookCore
33
import FacebookLogin
44
import FirebaseAuth
55
import FirebaseAuthSwiftUI
6+
import SwiftUI
67

78
let kFacebookEmailScope = "email"
89
let kFacebookProfileScope = "public_profile"
@@ -34,6 +35,10 @@ public class FacebookProviderSwift: FacebookProviderProtocol {
3435
shaNonce = CommonUtils.sha256Hash(of: rawNonce)
3536
}
3637

38+
@MainActor public var authButton: any View {
39+
return FacebookButtonView()
40+
}
41+
3742
@MainActor public func signInWithFacebook(isLimitedLogin: Bool) async throws -> AuthCredential {
3843
let trackingStatus = ATTrackingManager.trackingAuthorizationStatus
3944
let tracking: LoginTracking = trackingStatus != .authorized ? .limited :
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AuthService+Google.swift
3+
// FirebaseUI
4+
//
5+
// Created by Morgan Chen on 4/16/25.
6+
//
7+
8+
import FirebaseAuthSwiftUI
9+
10+
extension AuthService {
11+
12+
@discardableResult
13+
func withGoogleSignIn() -> AuthService {
14+
let clientID = auth.app?.options.clientID ?? ""
15+
self.googleProvider = GoogleProviderSwift(clientID: clientID)
16+
return self
17+
}
18+
19+
}

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/GoogleProviderSwift.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@preconcurrency import FirebaseAuth
22
import FirebaseAuthSwiftUI
33
import GoogleSignIn
4+
import GoogleSignInSwift
5+
import SwiftUI
46

57
let kGoogleUserInfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
68
let kGoogleUserInfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"
@@ -16,14 +18,24 @@ public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol {
1618
let scopes: [String]
1719
let shortName = "Google"
1820
let providerId = "google.com"
19-
public init(scopes: [String]? = nil) {
21+
let clientID: String
22+
public init(scopes: [String]? = nil, clientID: String) {
2023
self.scopes = scopes ?? kDefaultScopes
24+
self.clientID = clientID
2125
}
2226

2327
public func handleUrl(_ url: URL) -> Bool {
2428
return GIDSignIn.sharedInstance.handle(url)
2529
}
2630

31+
@MainActor public var authButton: any View {
32+
return GoogleSignInButton {
33+
Task {
34+
try await self.signInWithGoogle(clientID: self.clientID)
35+
}
36+
}
37+
}
38+
2739
@MainActor public func signInWithGoogle(clientID: String) async throws -> AuthCredential {
2840
guard let presentingViewController = await (UIApplication.shared.connectedScenes
2941
.first as? UIWindowScene)?.windows.first?.rootViewController else {

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ let package = Package(
277277
dependencies: [
278278
"FirebaseAuthSwiftUI",
279279
"GoogleSignIn",
280+
.product(name: "GoogleSignInSwift", package: "GoogleSignIn")
280281
],
281282
path: "FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources"
282283
),

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample.xcodeproj/project.pbxproj

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
/* Begin PBXBuildFile section */
1010
4607CC9C2D9BFE29009EC3F5 /* FirebaseAuthSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4607CC9B2D9BFE29009EC3F5 /* FirebaseAuthSwiftUI */; };
1111
4607CC9E2D9BFE29009EC3F5 /* FirebaseGoogleSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4607CC9D2D9BFE29009EC3F5 /* FirebaseGoogleSwiftUI */; };
12-
4670DEA72D9EA9E100E0D36A /* FirebaseFacebookSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4670DEA62D9EA9E100E0D36A /* FirebaseFacebookSwiftUI */; };
13-
46C4EAB32DA801B200FC878B /* FirebasePhoneAuthSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 46C4EAB22DA801B200FC878B /* FirebasePhoneAuthSwiftUI */; };
1412
46CB7B252D773F2100F1FD0A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 46CB7B242D773F2100F1FD0A /* GoogleService-Info.plist */; };
1513
46F89C392D64B04E000F8BC0 /* FirebaseAuthSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 46F89C382D64B04E000F8BC0 /* FirebaseAuthSwiftUI */; };
1614
46F89C4D2D64BB9B000F8BC0 /* FirebaseAuthSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 46F89C4C2D64BB9B000F8BC0 /* FirebaseAuthSwiftUI */; };
15+
8D808CB72DB0811900D2293F /* FirebaseFacebookSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 8D808CB62DB0811900D2293F /* FirebaseFacebookSwiftUI */; };
16+
8D808CB92DB081F900D2293F /* FirebasePhoneAuthSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 8D808CB82DB081F900D2293F /* FirebasePhoneAuthSwiftUI */; };
1717
/* End PBXBuildFile section */
1818

1919
/* Begin PBXContainerItemProxy section */
@@ -76,11 +76,11 @@
7676
isa = PBXFrameworksBuildPhase;
7777
buildActionMask = 2147483647;
7878
files = (
79-
4670DEA72D9EA9E100E0D36A /* FirebaseFacebookSwiftUI in Frameworks */,
79+
8D808CB72DB0811900D2293F /* FirebaseFacebookSwiftUI in Frameworks */,
8080
46F89C392D64B04E000F8BC0 /* FirebaseAuthSwiftUI in Frameworks */,
8181
46F89C4D2D64BB9B000F8BC0 /* FirebaseAuthSwiftUI in Frameworks */,
8282
4607CC9E2D9BFE29009EC3F5 /* FirebaseGoogleSwiftUI in Frameworks */,
83-
46C4EAB32DA801B200FC878B /* FirebasePhoneAuthSwiftUI in Frameworks */,
83+
8D808CB92DB081F900D2293F /* FirebasePhoneAuthSwiftUI in Frameworks */,
8484
4607CC9C2D9BFE29009EC3F5 /* FirebaseAuthSwiftUI in Frameworks */,
8585
);
8686
runOnlyForDeploymentPostprocessing = 0;
@@ -155,8 +155,8 @@
155155
46F89C4C2D64BB9B000F8BC0 /* FirebaseAuthSwiftUI */,
156156
4607CC9B2D9BFE29009EC3F5 /* FirebaseAuthSwiftUI */,
157157
4607CC9D2D9BFE29009EC3F5 /* FirebaseGoogleSwiftUI */,
158-
4670DEA62D9EA9E100E0D36A /* FirebaseFacebookSwiftUI */,
159-
46C4EAB22DA801B200FC878B /* FirebasePhoneAuthSwiftUI */,
158+
8D808CB62DB0811900D2293F /* FirebaseFacebookSwiftUI */,
159+
8D808CB82DB081F900D2293F /* FirebasePhoneAuthSwiftUI */,
160160
);
161161
productName = FirebaseSwiftUIExample;
162162
productReference = 46F89C082D64A86C000F8BC0 /* FirebaseSwiftUIExample.app */;
@@ -241,7 +241,7 @@
241241
mainGroup = 46F89BFF2D64A86C000F8BC0;
242242
minimizedProjectReferenceProxies = 1;
243243
packageReferences = (
244-
4607CC9A2D9BFE29009EC3F5 /* XCLocalSwiftPackageReference "../../../../firebaseUI-ios" */,
244+
8D808CB52DB07EBD00D2293F /* XCLocalSwiftPackageReference "../../../../FirebaseUI-iOS" */,
245245
);
246246
preferredProjectObjectVersion = 77;
247247
productRefGroup = 46F89C092D64A86C000F8BC0 /* Products */;
@@ -617,9 +617,9 @@
617617
/* End XCConfigurationList section */
618618

619619
/* Begin XCLocalSwiftPackageReference section */
620-
4607CC9A2D9BFE29009EC3F5 /* XCLocalSwiftPackageReference "../../../../firebaseUI-ios" */ = {
620+
8D808CB52DB07EBD00D2293F /* XCLocalSwiftPackageReference "../../../../FirebaseUI-iOS" */ = {
621621
isa = XCLocalSwiftPackageReference;
622-
relativePath = "../../../../firebaseUI-ios";
622+
relativePath = "../../../../FirebaseUI-iOS";
623623
};
624624
/* End XCLocalSwiftPackageReference section */
625625

@@ -632,16 +632,6 @@
632632
isa = XCSwiftPackageProductDependency;
633633
productName = FirebaseGoogleSwiftUI;
634634
};
635-
4670DEA62D9EA9E100E0D36A /* FirebaseFacebookSwiftUI */ = {
636-
isa = XCSwiftPackageProductDependency;
637-
package = 4607CC9A2D9BFE29009EC3F5 /* XCLocalSwiftPackageReference "../../../../firebaseUI-ios" */;
638-
productName = FirebaseFacebookSwiftUI;
639-
};
640-
46C4EAB22DA801B200FC878B /* FirebasePhoneAuthSwiftUI */ = {
641-
isa = XCSwiftPackageProductDependency;
642-
package = 4607CC9A2D9BFE29009EC3F5 /* XCLocalSwiftPackageReference "../../../../firebaseUI-ios" */;
643-
productName = FirebasePhoneAuthSwiftUI;
644-
};
645635
46F89C382D64B04E000F8BC0 /* FirebaseAuthSwiftUI */ = {
646636
isa = XCSwiftPackageProductDependency;
647637
productName = FirebaseAuthSwiftUI;
@@ -650,6 +640,16 @@
650640
isa = XCSwiftPackageProductDependency;
651641
productName = FirebaseAuthSwiftUI;
652642
};
643+
8D808CB62DB0811900D2293F /* FirebaseFacebookSwiftUI */ = {
644+
isa = XCSwiftPackageProductDependency;
645+
package = 8D808CB52DB07EBD00D2293F /* XCLocalSwiftPackageReference "../../../../FirebaseUI-iOS" */;
646+
productName = FirebaseFacebookSwiftUI;
647+
};
648+
8D808CB82DB081F900D2293F /* FirebasePhoneAuthSwiftUI */ = {
649+
isa = XCSwiftPackageProductDependency;
650+
package = 8D808CB52DB07EBD00D2293F /* XCLocalSwiftPackageReference "../../../../FirebaseUI-iOS" */;
651+
productName = FirebasePhoneAuthSwiftUI;
652+
};
653653
/* End XCSwiftPackageProductDependency section */
654654
};
655655
rootObject = 46F89C002D64A86C000F8BC0 /* Project object */;

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/FirebaseSwiftUIExampleApp.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import FirebasePhoneAuthSwiftUI
1515
import SwiftData
1616
import SwiftUI
1717

18-
let googleProvider = GoogleProviderSwift()
19-
2018
class AppDelegate: NSObject, UIApplicationDelegate {
2119
func application(_ application: UIApplication,
2220
didFinishLaunchingWithOptions launchOptions: [

0 commit comments

Comments
 (0)