简体   繁体   English

Flutter - Firebase Auth UID 在 Firestore 中注册为 Null

[英]Flutter - Firebase Auth UID registers as Null in Firestore

I have a code like this:我有这样的代码:

 try {
    await _auth.createUserWithEmailAndPassword(
      email: _emailController.text,
      password: _passwordController.text,
    );
    _firestore.collection("Users").doc(_auth.currentUser?.uid).set({
      "ID": _auth.currentUser?.uid, // Saved: Null
      "Email": _emailController.text,
      "Phone": _phoneController.text,
      "Name": _nameController.text,
      "Surname": _surnameController.text,
      "Photo": "https://firebasestorage.googleapis.com/v0/b/teen-software-stock-tracking.appspot.com/o/default.jpg?alt=media&token=0eec2e1f-2ccf-4bda-8664-3d3f018621b3",
      "Level": 0,
      "ProductRight": 10,
      "AddedProduct": 0,
      "AccountCreate": FullDate.toString(),
    });
    _auth.signOut();
    Get.offAll(const LoginPage());
  } on FirebaseAuthException catch (e) {
    // ...
  }

My goal is to save a few of the user's information in Firestore.我的目标是在 Firestore 中保存一些用户信息。 This information includes the user's UID.此信息包括用户的 UID。 But when saving it registers as Null in Firestore.但是当它在 Firestore 中保存为Null时。

Why could this be?为什么会这样? I would be glad if you help.如果你能帮忙,我会很高兴。 Thanks for your help in advance.提前感谢您的帮助。

To get the uid or other data of the newly created user try this:要获取新创建用户的uid或其他数据,请尝试以下操作:

final userCredential = await _auth.createUserWithEmailAndPassword(
  email: _emailController.text,
  password: _passwordController.text,
);

print(userCredential.user.uid);
print(userCredential.user.email);
// etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM