且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Flutter:使用从Firebase身份验证创建的帐户在Firestore中创建用户

更新时间:2022-06-10 07:24:20

您可以从AuthResult获取uid,以在Firestore中创建文档.setData更新文档,或者在这种情况下,创建一个文档,因为它不存在.确保安装cloud_firestore_package.

You can get the uid from AuthResult to create a document in Firestore. setData updates the document or in this case, creates one because it doesn't exist. Make sure to install cloud_firestore_package.

UserCredential result = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email, password: _password);
User user = result.user
await FirebaseFirestore.instance.collection('users')
      .doc(user.uid).set({ 'firstName': _firstName'})