Created [signIn] methos
This commit is contained in:
parent
00b3289e91
commit
d4e5228db1
2 changed files with 28 additions and 1 deletions
|
|
@ -100,4 +100,4 @@ class App extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,28 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class GoogleSignInProvider {
|
||||
final GoogleSignIn _googleSignIn;
|
||||
final FirebaseAuth _auth;
|
||||
|
||||
GoogleSignInProvider([GoogleSignIn googleSignIn, FirebaseAuth firebaseAuth])
|
||||
: _googleSignIn = googleSignIn ?? GoogleSignIn(),
|
||||
_auth = firebaseAuth ?? FirebaseAuth.instance;
|
||||
|
||||
Future<FirebaseUser> signIn() async {
|
||||
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
|
||||
final GoogleSignInAuthentication googleAuth =
|
||||
await googleUser.authentication;
|
||||
|
||||
final AuthCredential credential = GoogleAuthProvider.getCredential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
|
||||
final FirebaseUser user = await _auth.signInWithCredential(credential);
|
||||
print("signed in " + user.displayName);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue