File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
application/auth/sign_in_handler Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1
1
import 'package:dartz/dartz.dart' ;
2
+ import 'package:firebase_auth/firebase_auth.dart' ;
2
3
import 'package:flutter/foundation.dart' ;
3
4
import 'package:state_notifier/state_notifier.dart' ;
4
5
@@ -55,6 +56,7 @@ class SignInHandlerStateNotifier extends StateNotifier<SignInHandlerState>
55
56
isSubmitting: true ,
56
57
authFailureOrSuccessOption: none (),
57
58
);
59
+
58
60
final auth = await _authFacade.signInWithGoogle ();
59
61
60
62
if (mounted) {
@@ -65,6 +67,22 @@ class SignInHandlerStateNotifier extends StateNotifier<SignInHandlerState>
65
67
}
66
68
}
67
69
70
+ Future <void > signInWithCredential (AuthCredential credential) async {
71
+ state = state.copyWith (
72
+ isSubmitting: true ,
73
+ authFailureOrSuccessOption: none (),
74
+ );
75
+
76
+ final auth = await _authFacade.signInWithCredential (credential);
77
+
78
+ if (mounted) {
79
+ state = state.copyWith (
80
+ isSubmitting: false ,
81
+ authFailureOrSuccessOption: some (auth),
82
+ );
83
+ }
84
+ }
85
+
68
86
Future <void > signInAnonymously () async {
69
87
if (! _authProviders.anonymous) {
70
88
throw AuthProviderNotEnabled ('Anonymous' );
Original file line number Diff line number Diff line change
1
+ import 'package:firebase_auth/firebase_auth.dart' ;
1
2
import 'package:flutter/foundation.dart' ;
2
3
3
4
import 'auth.dart' ;
@@ -18,6 +19,7 @@ abstract class AuthFacade {
18
19
@required Password password,
19
20
});
20
21
Future <Auth > signInWithGoogle ();
22
+ Future <Auth > signInWithCredential (AuthCredential credential);
21
23
Future <Auth > signInAnonymously ();
22
24
Future <void > signOut ();
23
25
}
Original file line number Diff line number Diff line change @@ -250,6 +250,16 @@ class FirebaseAuthFacade implements AuthFacade {
250
250
}
251
251
}
252
252
253
+ @override
254
+ Future <Auth > signInWithCredential (AuthCredential credential) async {
255
+ try {
256
+ await _firebaseAuth.signInWithCredential (credential);
257
+ return const Auth .success ();
258
+ } on PlatformException catch (_) {
259
+ return const Auth .failure (AuthFailure .serverError ());
260
+ }
261
+ }
262
+
253
263
@override
254
264
Future <void > signOut () async {
255
265
return Future .wait ([
Original file line number Diff line number Diff line change
1
+ import 'package:firebase_auth/firebase_auth.dart' ;
1
2
import 'package:flutter/widgets.dart' ;
2
3
import 'package:provider/provider.dart' ;
3
4
@@ -40,6 +41,14 @@ extension AuthContext on BuildContext {
40
41
.signInWithGoogle ();
41
42
}
42
43
44
+ /// Sign in with Credentials
45
+ ///
46
+ /// Should only be used if your implementing your own third party sign-in
47
+ Future <void > signInWithCredential (AuthCredential credential) async {
48
+ Provider .of <SignInHandlerStateNotifier >(this , listen: false )
49
+ .signInWithCredential (credential);
50
+ }
51
+
43
52
/// Perform Firebase anonymous sign-in
44
53
///
45
54
/// Should only be used if you're creating your own custom sign-in form
You can’t perform that action at this time.
0 commit comments