Last active
August 4, 2020 14:45
-
-
Save sbis04/68bce48a4322b4fde0a837e6fa60df8b to your computer and use it in GitHub Desktop.
login_demo_4
This file contains hidden or 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
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
final FirebaseAuth _auth = FirebaseAuth.instance; | |
final GoogleSignIn googleSignIn = GoogleSignIn(); | |
Future<String> signInWithGoogle() async { | |
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn(); | |
final GoogleSignInAuthentication googleSignInAuthentication = | |
await googleSignInAccount.authentication; | |
final AuthCredential credential = GoogleAuthProvider.getCredential( | |
accessToken: googleSignInAuthentication.accessToken, | |
idToken: googleSignInAuthentication.idToken, | |
); | |
final AuthResult authResult = await _auth.signInWithCredential(credential); | |
final FirebaseUser user = authResult.user; | |
assert(!user.isAnonymous); | |
assert(await user.getIdToken() != null); | |
final FirebaseUser currentUser = await _auth.currentUser(); | |
assert(user.uid == currentUser.uid); | |
return 'signInWithGoogle succeeded: $user'; | |
} | |
void signOutGoogle() async{ | |
await googleSignIn.signOut(); | |
print("User Sign Out"); | |
} |
How to store user data such as name and email in firebase?
You can retrieve the user information like name, email, profile picture URL, etc. from the FirebaseUser
object.
Then, you can use Cloud Firestore to store the user information.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to store user data such as name and email in firebase?