Skip to content

Commit 6855e02

Browse files
Guilherme SouzaChrisChinchillagithub-actions[bot]
authored
docs(auth): add Flutter signInWithIdToken example for Facebook auth (supabase#38265)
* docs(auth): add Flutter signInWithIdToken example for Facebook auth Add documentation section showing how to integrate Facebook authentication in Flutter using the signInWithIdToken method with the Facebook SDK. Includes dependency setup, basic implementation, and error handling. * fix style * docs(dart): add Facebook signInWithIdToken example Add native Facebook sign-in example to the Dart client reference documentation. Includes integration with flutter_facebook_auth package and proper error handling for the signInWithIdToken method. * docs(dart): simplify provider parameter description Remove specific provider enumeration from parameter description to keep it more generic and maintainable. * Add signInWithIdToken to spelling allow list * Update auth-facebook.mdx Co-authored-by: Chris Chinchilla <[email protected]> * Update apps/docs/content/guides/auth/social-login/auth-facebook.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update apps/docs/content/guides/auth/social-login/auth-facebook.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Chris Chinchilla <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 5faa6b2 commit 6855e02

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

apps/docs/content/guides/auth/social-login/auth-facebook.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,55 @@ Future<void> signInWithFacebook() async {
121121
}
122122
```
123123

124+
### Alternative: Using Facebook SDK with signInWithIdToken
125+
126+
For more control over the Facebook authentication flow, you can use the Facebook SDK directly and then authenticate with Supabase using [`signInWithIdToken()`](/docs/reference/dart/auth-signinwithidtoken):
127+
128+
First, add the Facebook SDK dependency to your `pubspec.yaml`:
129+
130+
```yaml
131+
dependencies:
132+
flutter_facebook_auth: ^7.0.1
133+
```
134+
135+
Then implement the Facebook authentication:
136+
137+
```dart
138+
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
139+
import 'package:supabase_flutter/supabase_flutter.dart';
140+
141+
Future<void> signInWithFacebook() async {
142+
try {
143+
final LoginResult result = await FacebookAuth.instance.login(
144+
permissions: ['public_profile', 'email'],
145+
);
146+
147+
if (result.status == LoginStatus.success) {
148+
final accessToken = result.accessToken!.tokenString;
149+
150+
await Supabase.instance.client.auth.signInWithIdToken(
151+
provider: OAuthProvider.facebook,
152+
idToken: accessToken,
153+
);
154+
155+
// Authentication successful
156+
} else {
157+
// Handle login cancellation or failure
158+
throw Exception('Facebook login failed: ${result.status}');
159+
}
160+
} catch (e) {
161+
// Handle errors
162+
throw Exception('Facebook authentication error: ${e.toString()}');
163+
}
164+
}
165+
```
166+
167+
<Admonition type="note">
168+
169+
Make sure to configure your Facebook app properly and add the required permissions in the Facebook Developer Console. The `signInWithIdToken` method requires the Facebook access token to be valid and properly scoped.
170+
171+
</Admonition>
172+
124173
</TabPanel>
125174
<TabPanel id="swift" label="Swift">
126175

apps/docs/spec/supabase_dart_v2.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,12 @@ functions:
558558
- id: sign-in-with-id-token
559559
title: 'signInWithIdToken()'
560560
description: |
561-
Allows you to perform native Google and Apple sign in by combining it with [google_sign_in](https://pub.dev/packages/google_sign_in) or [sign_in_with_apple](https://pub.dev/packages/sign_in_with_apple) packages.
561+
Allows you to perform native Google, Apple, and Facebook sign in by combining it with [google_sign_in](https://pub.dev/packages/google_sign_in), [sign_in_with_apple](https://pub.dev/packages/sign_in_with_apple), or [flutter_facebook_auth](https://pub.dev/packages/flutter_facebook_auth) packages.
562562
params:
563563
- name: provider
564564
isOptional: false
565565
type: OAuthProvider
566-
description: The provider to perform the sign in with. Currently, `OAuthProvider.google` and `OAuthProvider.apple` are supported.
566+
description: The provider to perform the sign in with.
567567
- name: idToken
568568
isOptional: false
569569
type: String
@@ -719,6 +719,36 @@ functions:
719719
nonce: rawNonce,
720720
);
721721
```
722+
- id: sign-in-with-facebook
723+
name: Native Facebook Sign in
724+
description: |
725+
You can perform native Facebook sign in using [flutter_facebook_auth](https://pub.dev/packages/flutter_facebook_auth).
726+
727+
First, set up your Facebook app in the [Facebook Developer Console](https://developers.facebook.com) and configure it in your Supabase dashboard under `Authentication -> Providers -> Facebook`.
728+
code: |
729+
```dart
730+
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
731+
import 'package:supabase_flutter/supabase_flutter.dart';
732+
733+
Future<void> signInWithFacebook() async {
734+
final LoginResult result = await FacebookAuth.instance.login(
735+
permissions: ['public_profile', 'email'],
736+
);
737+
738+
if (result.status == LoginStatus.success) {
739+
final accessToken = result.accessToken!.tokenString;
740+
741+
final response = await supabase.auth.signInWithIdToken(
742+
provider: OAuthProvider.facebook,
743+
idToken: accessToken,
744+
);
745+
} else {
746+
throw const AuthException(
747+
'Facebook login failed: ${result.status}',
748+
);
749+
}
750+
}
751+
```
722752
- id: sign-in-with-oauth
723753
title: 'signInWithOAuth()'
724754
description: |

supa-mdx-lint/Rule003Spelling.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ allow_list = [
336336
"psql",
337337
"scrypt",
338338
"sessionStorage",
339+
"signInWithIdToken",
339340
"stdin",
340341
"stdout",
341342
"[Ss]ubnet(s)?",

0 commit comments

Comments
 (0)