Last active
June 11, 2022 11:05
-
-
Save mbevin/393597735c67575eccf0858c4c17168d to your computer and use it in GitHub Desktop.
Flutterfire patch to save appleCredentials to SharedPreferences, done on top of flutterfire_ui 0.4.0+5 (5c40fa1aa36aee0bea6cb15c40a201bcf0685d35)
This file contains 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
diff --git a/packages/flutterfire_ui/.vscode/settings.json b/packages/flutterfire_ui/.vscode/settings.json | |
new file mode 100644 | |
index 00000000..f1d07a3f | |
--- /dev/null | |
+++ b/packages/flutterfire_ui/.vscode/settings.json | |
@@ -0,0 +1,9 @@ | |
+{ | |
+ "editor.wordWrapColumn": 80, | |
+ "dart.lineLength": 80, | |
+ "[dart]": { | |
+ "editor.rulers": [ | |
+ 80 | |
+ ], | |
+ } | |
+} | |
\ No newline at end of file | |
diff --git a/packages/flutterfire_ui/lib/src/auth/oauth/providers/apple_provider.dart b/packages/flutterfire_ui/lib/src/auth/oauth/providers/apple_provider.dart | |
index 27841aa2..05d215f1 100644 | |
--- a/packages/flutterfire_ui/lib/src/auth/oauth/providers/apple_provider.dart | |
+++ b/packages/flutterfire_ui/lib/src/auth/oauth/providers/apple_provider.dart | |
@@ -1,3 +1,4 @@ | |
+import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:math'; | |
@@ -6,6 +7,7 @@ import 'package:desktop_webview_auth/desktop_webview_auth.dart'; | |
import 'package:firebase_auth/firebase_auth.dart' as fba; | |
import 'package:flutterfire_ui/i10n.dart'; | |
import 'package:flutter/foundation.dart'; | |
+import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:sign_in_with_apple/sign_in_with_apple.dart'; | |
import '../../widgets/apple_sign_in_button.dart' show AppleProviderButtonStyle; | |
@@ -34,6 +36,19 @@ String sha256ofString(String input) { | |
abstract class AppleProvider extends OAuthProvider {} | |
class AppleProviderImpl extends AppleProvider { | |
+ Future<void> saveToSharedPreferences( | |
+ AuthorizationCredentialAppleID appleCredential, | |
+ ) async { | |
+ final prefs = await SharedPreferences.getInstance(); | |
+ | |
+ if ((appleCredential.givenName ?? '').isNotEmpty) { | |
+ await prefs.setString('userFirstName', appleCredential.givenName!); | |
+ } | |
+ if ((appleCredential.familyName ?? '').isNotEmpty) { | |
+ await prefs.setString('userLastName', appleCredential.familyName!); | |
+ } | |
+ } | |
+ | |
@override | |
Future<fba.OAuthCredential> signIn() async { | |
final rawNonce = generateNonce(); | |
@@ -48,6 +63,8 @@ class AppleProviderImpl extends AppleProvider { | |
nonce: nonce, | |
); | |
+ unawaited(saveToSharedPreferences(appleCredential)); | |
+ | |
// Create an `OAuthCredential` from the credential returned by Apple. | |
final oauthCredential = fba.OAuthProvider('apple.com').credential( | |
idToken: appleCredential.identityToken, | |
diff --git a/packages/flutterfire_ui/pubspec.yaml b/packages/flutterfire_ui/pubspec.yaml | |
index 1244fa73..23fb0bf0 100644 | |
--- a/packages/flutterfire_ui/pubspec.yaml | |
+++ b/packages/flutterfire_ui/pubspec.yaml | |
@@ -28,6 +28,7 @@ dependencies: | |
sdk: flutter | |
flutter_svg: ^1.0.0 | |
google_sign_in: ^5.2.1 | |
+ shared_preferences: ^2.0.15 | |
sign_in_with_apple: ^3.3.0 | |
twitter_login: ^4.2.2 | |
@@ -47,6 +48,7 @@ flutter: | |
assets: | |
- assets/icons/ | |
- assets/countries.json | |
+ | |
# To add assets to your package, add an assets section, like this: | |
# assets: | |
# - images/a_dot_burr.jpeg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment