-
-
Notifications
You must be signed in to change notification settings - Fork 166
chore: add Facebook Auth example #729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
grdsdev
wants to merge
3
commits into
main
Choose a base branch
from
guilherme/example-facebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import FacebookLogin | ||
import OSLog | ||
import Supabase | ||
import SwiftUI | ||
|
||
let logger = Logger(subsystem: "com.supabase.examples", category: "SignInWithFacebook") | ||
|
||
struct SignInWithFacebook: View { | ||
@State private var actionState = ActionState<Void, Error>.idle | ||
|
||
let loginManager = LoginManager() | ||
|
||
var body: some View { | ||
VStack { | ||
Button("Sign in with Facebook") { | ||
actionState = .inFlight | ||
|
||
loginManager.logIn( | ||
configuration: LoginConfiguration( | ||
permissions: ["public_profile", "email"], | ||
tracking: .limited | ||
) | ||
) { result in | ||
switch result { | ||
case .failed(let error): | ||
actionState = .result(.failure(error)) | ||
logger.error("Facebook login failed: \(error.localizedDescription)") | ||
case .cancelled: | ||
actionState = .idle | ||
logger.info("Facebook login cancelled") | ||
case .success(_, _, let token): | ||
logger.info("Facebook login succeeded.") | ||
|
||
guard let idToken = token?.tokenString else { | ||
actionState = .idle | ||
logger.error("Facebook login token is nil") | ||
return | ||
} | ||
|
||
Task { | ||
do { | ||
try await supabase.auth.signInWithIdToken( | ||
credentials: OpenIDConnectCredentials( | ||
provider: .facebook, | ||
idToken: idToken | ||
) | ||
) | ||
actionState = .result(.success(())) | ||
logger.info("Successfully signed in with Facebook") | ||
} catch { | ||
actionState = .result(.failure(error)) | ||
logger.error("Failed to sign in with Facebook: \(error.localizedDescription)") | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SignInWithFacebook() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Examples | ||
|
||
This directory contains example applications demonstrating the usage of Supabase Swift SDK. | ||
|
||
## Prerequisites | ||
|
||
[Requirements](../README.md#requirements) | ||
|
||
## Running the Examples App | ||
|
||
1. Open the `Examples.xcodeproj` file in Xcode | ||
2. Select your target device or simulator | ||
3. Build and run the project (⌘R) | ||
|
||
## Authentication Setup | ||
|
||
### Supabase Credentials Setup | ||
|
||
The examples app uses a local Supabase instance by default. To set up your Supabase credentials: | ||
|
||
1. Open `Supabase.plist` in the Examples project | ||
2. Update the following values: | ||
- `SUPABASE_URL`: Your Supabase project URL | ||
- `SUPABASE_ANON_KEY`: Your Supabase project's anon/public key | ||
|
||
You can find these values in your Supabase project dashboard under Project Settings > API. | ||
|
||
### Google Sign-In Setup | ||
|
||
To enable Google Sign-In in the examples app: | ||
|
||
1. Create a project in the [Google Cloud Console](https://console.cloud.google.com/) | ||
2. Enable the Google Sign-In API | ||
3. Create OAuth 2.0 credentials for iOS | ||
4. Update the `Info.plist` file with your credentials: | ||
- Replace `{{ YOUR_IOS_CLIENT_ID }}` with your iOS client ID | ||
- Replace `{{ YOUR_SERVER_CLIENT_ID }}` with your server client ID | ||
- Replace `{{ DOT_REVERSED_IOS_CLIENT_ID }}` with your reversed client ID | ||
|
||
### Facebook Sign-In Setup | ||
|
||
To enable Facebook Sign-In in the examples app: | ||
|
||
1. Create an app in the [Facebook Developers Console](https://developers.facebook.com/) | ||
2. Add iOS platform to your Facebook app | ||
3. Update the `Info.plist` file with your Facebook credentials: | ||
- Replace `{{ FACEBOOK APP ID }}` with your Facebook App ID | ||
- Replace `{{ FACEBOOK CLIENT TOKEN }}` with your Facebook Client Token |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Scope the logger by declaring it as a
private static
property inside theSignInWithFacebook
struct to avoid polluting the global namespace.Copilot uses AI. Check for mistakes.