我有一個按鈕可以讓用戶洗掉他們的帳戶。當用戶注冊他們的電子郵件并將姓名保存到名為 users 的 Firestore 集合時,我想在集合的檔案中搜索 uid 欄位等于當前用戶 uid 的檔案,然后洗掉該檔案。洗掉帳戶有效,但檔案無效,我沒有收到任何錯誤,我不確定我做錯了什么......
CollectionReference users = FirebaseFirestore.instance.collection('users');
TextButton(
onPressed: () async {
try {
await users
.where('uid', isEqualTo: _auth.currentUser!.uid).firestore.doc(users.doc().path).delete();
await _auth.currentUser!.delete().then((value) =>
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => const WelcomeScreen())));
} on FirebaseAuthException catch (error) {
Fluttertoast.showToast( msg: error.message.toString(),
gravity: ToastGravity.TOP,
backgroundColor: Colors.red,
textColor: Colors.white);
} on FirebaseException catch (error) { Fluttertoast.showToast(
msg: error.message.toString(),
gravity: ToastGravity.TOP,
backgroundColor: Colors.red,
textColor: Colors.white);
}
},
child: const Text( 'Delete', style: TextStyle(color: Colors.red),
))
uj5u.com熱心網友回復:
我遇到了問題,我只是在我的應用程式上作業并找到了類似的代碼,所以這里是解決方案。只需將用戶 ID 宣告為變數即可,無需像這樣(可選)
final uid = _auth.currentUser!.uid; //optional
然后在您的代碼中使用它:-
await users.doc(uid).delete();
代替
await users
.where('uid', isEqualTo: _auth.currentUser!.uid).firestore.doc(users.doc().path).delete();
和 Boom 現在它就像一個魅力!希望這有效!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/364071.html
標籤:火力基地 扑 镖 谷歌云firestore Firebase 身份验证
