我正在使用具有注册屏幕的Flutter应用程序。我已经实现了电子邮件身份验证,并想检查用户是否已经注册? 我用过:
final newUser = await _auth.createUserWithEmailAndPassword(email: email.trim(),password: password);
注册用户。如果用户已经注册,则抛出错误,认为该天的电子邮件已经在使用中,但是我要自定义消息。 那么,如何通过提供特定的电子邮件从Firebase集合中检索特定的用户数据(例如电子邮件)? 例如:在注册电话之前,是否要从集合中查询指定的电子邮件是否已使用?
我也尝试过fetchSignInMethodsForEmail
,但没有得到任何结果。
答案 0 :(得分:0)
解决了!
Future<void> isEmailRegistered(String email) async {
final QuerySnapshot result = await Firestore.instance
.collection('users')
.where('userEmail', isEqualTo: email)
.limit(1)
.getDocuments();
final List<DocumentSnapshot> documents = result.documents;
if (documents.length > 0)
print('Email is in Use');
else
print('Email is not in Use');
}