docs: Add Flutter code sample for Firebase Auth integration guide (#31087)

* docs: Add Flutter code sample for accessToken function

* docs: fix the code sample
This commit is contained in:
Tyler authored and GitHub committed 2025-02-05 10:16:15 +09:00
1 parent 95594570b0
commit af7d12cedb
1 file changed
+20
@@ -36,6 +36,26 @@ Make sure the all users in your application have the `role: 'authenticated'` [cu
</TabPanel>
<TabPanel id="dart" label="Flutter">
Creating a client for the Web is as easy as passing the `accessToken` async function. This function should [return the Firebase Auth JWT of the current user](https://firebase.google.com/docs/auth/admin/verify-id-tokens) (or null if no such user) is found.
```dart
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseKey,
debug: false,
accessToken: () async {
final token = await FirebaseAuth.instance.currentUser?.getIdToken();
return token;
},
);
```
Make sure the all users in your application have the `role: 'authenticated'` [custom claim](https://firebase.google.com/docs/auth/admin/custom-claims) set. If you're using the `onCreate` Cloud Function to add this custom claim to newly signed up users, you will need to call `getIdToken(/* forceRefresh */ true)` immediately after sign up as the `onCreate` function does not run synchronously.
</TabPanel>
<TabPanel id="swift" label="Swift (iOS)">
```swift