Skip to content

Commit 4679d65

Browse files
committed
chore: add Facebook Auth example
1 parent 340d769 commit 4679d65

File tree

6 files changed

+160
-3
lines changed

6 files changed

+160
-3
lines changed

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
7956406A2955AFBD0088A06F /* ErrorText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640692955AFBD0088A06F /* ErrorText.swift */; };
2929
7956406D2955B3500088A06F /* SwiftUINavigation in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406C2955B3500088A06F /* SwiftUINavigation */; };
3030
795640702955B5190088A06F /* IdentifiedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406F2955B5190088A06F /* IdentifiedCollections */; };
31+
795FA98B2DF353AF00F67AFF /* SignInWithFacebook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795FA98A2DF353AC00F67AFF /* SignInWithFacebook.swift */; };
32+
795FA98E2DF354B000F67AFF /* FacebookLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 795FA98D2DF354B000F67AFF /* FacebookLogin */; };
3133
796298992AEBBA77000AA957 /* MFAFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796298982AEBBA77000AA957 /* MFAFlow.swift */; };
3234
7962989D2AEBC6F9000AA957 /* SVGView in Frameworks */ = {isa = PBXBuildFile; productRef = 7962989C2AEBC6F9000AA957 /* SVGView */; };
3335
79719ECE2ADF26C400737804 /* Supabase in Frameworks */ = {isa = PBXBuildFile; productRef = 79719ECD2ADF26C400737804 /* Supabase */; };
@@ -102,6 +104,7 @@
102104
795640652955AE9C0088A06F /* TodoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListView.swift; sourceTree = "<group>"; };
103105
795640672955AEB30088A06F /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = "<group>"; };
104106
795640692955AFBD0088A06F /* ErrorText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorText.swift; sourceTree = "<group>"; };
107+
795FA98A2DF353AC00F67AFF /* SignInWithFacebook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInWithFacebook.swift; sourceTree = "<group>"; };
105108
796298982AEBBA77000AA957 /* MFAFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFAFlow.swift; sourceTree = "<group>"; };
106109
7962989A2AEBBD9F000AA957 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
107110
797D66492B46A1D8007592ED /* Dependencies.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dependencies.swift; sourceTree = "<group>"; };
@@ -158,6 +161,7 @@
158161
isa = PBXFrameworksBuildPhase;
159162
buildActionMask = 2147483647;
160163
files = (
164+
795FA98E2DF354B000F67AFF /* FacebookLogin in Frameworks */,
161165
79BE42A12D942EFD00B9DDF4 /* Clerk in Frameworks */,
162166
79E2B5582B97890F0042CD21 /* GoogleSignIn in Frameworks */,
163167
795640702955B5190088A06F /* IdentifiedCollections in Frameworks */,
@@ -270,6 +274,7 @@
270274
79AF04822B2CE3BD008761AD /* Auth */ = {
271275
isa = PBXGroup;
272276
children = (
277+
795FA98A2DF353AC00F67AFF /* SignInWithFacebook.swift */,
273278
799EE6A22C877BF900FD9DD7 /* SignInWithPhone.swift */,
274279
7956405F2954AE140088A06F /* AuthController.swift */,
275280
79AF04802B2CE261008761AD /* AuthView.swift */,
@@ -376,6 +381,7 @@
376381
79E2B5572B97890F0042CD21 /* GoogleSignIn */,
377382
79E2B5592B97890F0042CD21 /* GoogleSignInSwift */,
378383
79BE42A02D942EFD00B9DDF4 /* Clerk */,
384+
795FA98D2DF354B000F67AFF /* FacebookLogin */,
379385
);
380386
productName = Examples;
381387
productReference = 793895C62954ABFF0044F2B8 /* Examples.app */;
@@ -458,6 +464,7 @@
458464
7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */,
459465
79E2B5562B97890F0042CD21 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */,
460466
79BE429F2D942EFD00B9DDF4 /* XCRemoteSwiftPackageReference "clerk-ios" */,
467+
795FA98C2DF354B000F67AFF /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */,
461468
);
462469
productRefGroup = 793895C72954ABFF0044F2B8 /* Products */;
463470
projectDirPath = "";
@@ -510,6 +517,7 @@
510517
799EE6A32C877BFB00FD9DD7 /* SignInWithPhone.swift in Sources */,
511518
79AF04862B2CE586008761AD /* Debug.swift in Sources */,
512519
79AF04842B2CE408008761AD /* AuthWithMagicLink.swift in Sources */,
520+
795FA98B2DF353AF00F67AFF /* SignInWithFacebook.swift in Sources */,
513521
79401F352BC708C8004C9C0F /* UIViewControllerWrapper.swift in Sources */,
514522
79401F332BC6FEAE004C9C0F /* SignInWithOAuth.swift in Sources */,
515523
79B1C80E2BAC017C00D991AA /* AnyJSONView.swift in Sources */,
@@ -991,6 +999,14 @@
991999
minimumVersion = 1.0.0;
9921000
};
9931001
};
1002+
795FA98C2DF354B000F67AFF /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */ = {
1003+
isa = XCRemoteSwiftPackageReference;
1004+
repositoryURL = "https://github.com/facebook/facebook-ios-sdk";
1005+
requirement = {
1006+
kind = upToNextMajorVersion;
1007+
minimumVersion = 14.1.0;
1008+
};
1009+
};
9941010
7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */ = {
9951011
isa = XCRemoteSwiftPackageReference;
9961012
repositoryURL = "https://github.com/exyte/SVGView";
@@ -1028,6 +1044,11 @@
10281044
package = 7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */;
10291045
productName = IdentifiedCollections;
10301046
};
1047+
795FA98D2DF354B000F67AFF /* FacebookLogin */ = {
1048+
isa = XCSwiftPackageProductDependency;
1049+
package = 795FA98C2DF354B000F67AFF /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */;
1050+
productName = FacebookLogin;
1051+
};
10311052
7962989C2AEBC6F9000AA957 /* SVGView */ = {
10321053
isa = XCSwiftPackageProductDependency;
10331054
package = 7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */;

Examples/Examples/Auth/AuthView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct AuthView: View {
1313
case magicLink
1414
case signInWithPhone
1515
case signInWithApple
16+
case signInWithFacebook
1617
case signInWithOAuth
1718
#if canImport(UIKit)
1819
case signInWithOAuthUsingUIKit
@@ -26,6 +27,7 @@ struct AuthView: View {
2627
case .magicLink: "Auth with Magic Link"
2728
case .signInWithPhone: "Sign in with Phone"
2829
case .signInWithApple: "Sign in with Apple"
30+
case .signInWithFacebook: "Sign in with Facebook"
2931
case .signInWithOAuth: "Sign in with OAuth flow"
3032
#if canImport(UIKit)
3133
case .signInWithOAuthUsingUIKit: "Sign in with OAuth flow (UIKit)"
@@ -61,6 +63,7 @@ extension AuthView.Option: View {
6163
case .magicLink: AuthWithMagicLink()
6264
case .signInWithPhone: SignInWithPhone()
6365
case .signInWithApple: SignInWithApple()
66+
case .signInWithFacebook: SignInWithFacebook()
6467
case .signInWithOAuth: SignInWithOAuth()
6568
#if canImport(UIKit)
6669
case .signInWithOAuthUsingUIKit: UIViewControllerWrapper(SignInWithOAuthViewController())
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import FacebookLogin
2+
import OSLog
3+
import Supabase
4+
import SwiftUI
5+
6+
let logger = Logger(subsystem: "com.supabase.examples", category: "SignInWithFacebook")
7+
8+
struct SignInWithFacebook: View {
9+
@State private var actionState = ActionState<Void, Error>.idle
10+
11+
let loginManager = LoginManager()
12+
13+
var body: some View {
14+
VStack {
15+
Button("Sign in with Facebook") {
16+
actionState = .inFlight
17+
18+
loginManager.logIn(
19+
configuration: LoginConfiguration(
20+
permissions: ["public_profile", "email"],
21+
tracking: .limited
22+
)
23+
) { result in
24+
switch result {
25+
case .failed(let error):
26+
actionState = .result(.failure(error))
27+
logger.error("Facebook login failed: \(error.localizedDescription)")
28+
case .cancelled:
29+
actionState = .idle
30+
logger.info("Facebook login cancelled")
31+
case .success(_, _, let token):
32+
logger.info("Facebook login succeeded.")
33+
34+
guard let idToken = token?.tokenString else {
35+
actionState = .idle
36+
logger.error("Facebook login token is nil")
37+
return
38+
}
39+
40+
Task {
41+
do {
42+
try await supabase.auth.signInWithIdToken(
43+
credentials: OpenIDConnectCredentials(
44+
provider: .facebook,
45+
idToken: idToken
46+
)
47+
)
48+
actionState = .result(.success(()))
49+
logger.info("Successfully signed in with Facebook")
50+
} catch {
51+
actionState = .result(.failure(error))
52+
logger.error("Failed to sign in with Facebook: \(error.localizedDescription)")
53+
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
#Preview {
64+
SignInWithFacebook()
65+
}

Examples/Examples/ExamplesApp.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,54 @@
55
// Created by Guilherme Souza on 22/12/22.
66
//
77

8+
import FacebookLogin
89
import GoogleSignIn
910
import Supabase
1011
import SwiftUI
12+
import UIKit
13+
14+
final class AppDelegate: UIResponder, UIApplicationDelegate {
15+
func application(
16+
_ application: UIApplication,
17+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
18+
) -> Bool {
19+
ApplicationDelegate.shared.application(
20+
application,
21+
didFinishLaunchingWithOptions: launchOptions
22+
)
23+
}
24+
25+
func application(
26+
_ application: UIApplication,
27+
configurationForConnecting connectingSceneSession: UISceneSession,
28+
options: UIScene.ConnectionOptions
29+
) -> UISceneConfiguration {
30+
let sceneConfig = UISceneConfiguration(
31+
name: "Default Configuration",
32+
sessionRole: connectingSceneSession.role
33+
)
34+
sceneConfig.delegateClass = SceneDelegate.self
35+
return sceneConfig
36+
}
37+
}
38+
39+
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
40+
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
41+
guard let url = URLContexts.first?.url else { return }
42+
43+
ApplicationDelegate.shared.application(
44+
UIApplication.shared,
45+
open: url,
46+
sourceApplication: nil,
47+
annotation: [UIApplication.OpenURLOptionsKey.annotation]
48+
)
49+
}
50+
}
1151

1252
@main
1353
struct ExamplesApp: App {
54+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
55+
1456
var body: some Scene {
1557
WindowGroup {
1658
RootView()

Examples/Examples/Info.plist

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,30 @@
1717
<string>Editor</string>
1818
<key>CFBundleURLSchemes</key>
1919
<array>
20-
<string>DOT_REVERSED_IOS_CLIENT_ID</string>
20+
<string>{{ DOT_REVERSED_IOS_CLIENT_ID }}</string>
2121
</array>
2222
</dict>
23+
<dict>
24+
<key>CFBundleURLSchemes</key>
25+
<array>
26+
<string>fb{{ FACEBOOK APP ID }}</string>
27+
</array>
28+
</dict>
2329
</array>
2430
<key>GIDClientID</key>
25-
<string>YOUR_IOS_CLIENT_ID</string>
31+
<string>{{ YOUR_IOS_CLIENT_ID }}</string>
2632
<key>GIDServerClientID</key>
27-
<string>YOUR_SERVER_CLIENT_ID</string>
33+
<string>{{ YOUR_SERVER_CLIENT_ID }}</string>
34+
<key>FacebookAppID</key>
35+
<string>{{ FACEBOOK APP ID }}</string>
36+
<key>FacebookClientToken</key>
37+
<string>{{ FACEBOOK CLIENT TOKEN }}</string>
38+
<key>FacebookDisplayName</key>
39+
<string>Examples</string>
40+
<key>LSApplicationQueriesSchemes</key>
41+
<array>
42+
<string>fbapi</string>
43+
<string>fb-messenger-share-api</string>
44+
</array>
2845
</dict>
2946
</plist>

Supabase.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)