firebase - 我无法正确验证 Firebase 用户并在 Flutter 中显示错误消息
问题描述
我可以很好地对用户进行身份验证,但是,当我故意输入一个不存在的电子邮件地址或正确的电子邮件地址但密码错误时,身份验证错误消息似乎有延迟。
我最初尝试使用 Future、async 和 await 在里面,但是按照 udemy 教程,他没有使用它,所以我把它拿走了,但它的运行方式没有区别。我正在做的与教程中不同的一件事是我也在更新云存储数据库。
loginUser(_email, _password) {
formkey.currentState.save();
if (formkey.currentState.validate()) {
_auth
.signInWithEmailAndPassword(email: _email, password: _password)
.catchError((e) {
Fluttertoast.showToast(
msg: e.message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.TOP,
timeInSecForIos: 5,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
}).then((newUser) {
var now = new DateTime.now();
Firestore.instance
.collection('users')
.document(newUser.uid)
.collection('userInfo')
.document('userInfo')
.setData({
'Last login': now,
})
.then((onValue) {
print('Created it in sub collection');
}).catchError((e) {
print('======Error======== ' + e);
});
getSignedInUser();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyApp()),
);
});
}
}
getSignedInUser() async {
mCurrentUser = await _auth.currentUser();
DocumentSnapshot result = await Firestore.instance.collection('users')
.document(mCurrentUser.uid).collection('profile').document('profile')
.get();
String myResult = result['First Name'];
Fluttertoast.showToast(
msg: "Welcome $myResult!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.TOP,
timeInSecForIos: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
}
}
我第一次输入无效的电子邮件时,我在控制台中收到错误,说明在 null 上调用 e.message 的行。如果我再次按登录,它会给我正确的错误消息。现在,如果我输入了正确的电子邮件地址,但密码错误(在同一个运行实例中)。它说用户名不存在。如果我再次单击它,它会给我正确的无效密码消息。任何想法我做错了什么?提前致谢
解决方案
推荐阅读
- android - 如何使用 ViewModel 在 Fragment 之间进行通信?
- html - 如何将 html 中的变量字符串值渲染到烧瓶中?
- python - 使用先知的时间序列预测(来自`float`的issubdtype)
- javascript - 页面重新加载时滚动事件未触发
- php - 如何仅获取列表中不同的城市?
- mysql - MySQL:别名表不存在(复杂的子查询)
- ios - 解析 NSURL 方案 iOS
- angularjs - 日期过滤器导致 ng-repeat+其他过滤器在 IE11 中非常慢
- jakarta-ee - Java EE @ApplicationScoped 与单例模式
- node.js - Webpack + Typescript + watch 仅在重新编译时导致错误 TS2554