-
Notifications
You must be signed in to change notification settings - Fork 2
/
authService.dart
41 lines (31 loc) · 1.08 KB
/
authService.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
class AuthProvider {
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<bool> signInWithGoogle() async {
GoogleSignInAccount _googleSignInAccount;
try {
_googleSignInAccount = await _googleSignIn.signIn();
}
catch(e) {
print(e.toString());
return false;
}
if (_googleSignInAccount == null) return false;
GoogleSignInAuthentication googleSignInAuthentication =
await _googleSignInAccount.authentication;
AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
AuthResult authResult = await _auth.signInWithCredential(credential);
if (authResult.user == null) return false;
print("signInWithGoogle succeeded");
return true;
}
Future<void> signOutGoogle() async {
await _auth.signOut();
print("signOutWithGoogle succeeded");
}
}