I am using google auth and i want to save user data in database…How can i get user details here and save it to database?
Future<void> signUpWithGoogle(
BuildContext context,
bool mounted,
) async {
final googleSignIn = GoogleSignIn();
final googleUser = await googleSignIn.signIn();
if (googleUser == null) return;
final googleAuth = await googleUser.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
try {
await FirebaseAuth.instance.signInWithCredential(credential);
FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.set({
//
});
if (mounted) return;
InfoBox.show(context, InfoBox.success, "Signed In With Google");
} on Exception catch (e) {
if (mounted) return;
InfoBox.show(context, InfoBox.success, e.toString());
}
}
2
Answers
Please modify the code under your try block as below
Please accept the solution if it solves your problem
Inside your try block, you have to get UserCredential which gives the User object data to be saved in the next line.
You can use
user
object to get all the necessary data.