How to set firebase uid to users document id? i'm getting error as "uid is null". Here is my code.
FirebaseAuth.instance.createUserWithEmailAndPassword(email:email, password: password).then((currentUser) => Firestore.instance
.collection("users")
.document(currentUser.uid)
.setData({ "uid": currentUser.uid,
}));
You can become the current user information with the.user ending and then you have access to the uid with currentUser.uid.
Future<void> createUser() async {
final FirebaseUser currentUser = (await FirebaseAuth.instance.createUserWithEmailAndPassword(email: 'Test@gmail.com', password: '123456')).user;
Firestore.instance.collection("users").document(currentUser.uid).setData({
"uid": currentUser.uid,
},
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.