firebase - 如何使用 Flutter 在 Firebase 中正确登录和注册?
问题描述
我有这个应用程序可以通过firebase +电子邮件验证进行登录和注册,但当用户输入用户名,电子邮件,密码时,效率不是很高,......即使电子邮件错误,它也会注册所以我搜索并在firebase中找到了一个电子邮件验证的解决方案,但问题是如果用户没有验证,Firebase会注册它并且他可以登录(即使电子邮件无效),所以有什么想法吗?也是新手。我在注册页面中执行的注册代码:
static Future signup(String email, String password, BuildContext ctx) async {
String emessage;
if (email == '' || password == '') {
emessage = 'Please Provide Valid Email And Password';
} else {
emessage = 'An Error Occurred. Please Try Again Later.';
}
try {
final FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
))
.user;
user.sendEmailVerification();
return user.uid;
} catch (e) {
showDialog(
context: ctx,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Error'),
content: Text(emessage),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text('Ok'),
),
],
);
});
}
}
解决方案
Firebase 文档没有createUserWithEmailAndPassword
列出任何强制预先电子邮件验证的参数。
你可以
- 首次登录后使用
signInWithEmailLink
并添加密码。 - 禁止没有经过验证的电子邮件地址的用户访问您应用中的内容——就像您对未经验证的用户执行此操作一样。
推荐阅读
- react-native - 如何在卡片上方显示组件图像
- bash - 将所有输出重定向到 lolcat
- javascript - css 溢出:隐藏导致鼠标 layerX & layerY 位置不正确
- android - 在 recyclerview 的第一项滚动到屏幕外后显示工具栏
- javascript - 如何将 csv 转换为 json 并编写特定函数以使用 javascript 生成图形?
- android - Android Studio (AS) 和 Emulator 工作正常,但 AS 无法识别模拟器
- android - 为什么你必须在 RxJava 中的 CompositeDisposable 上处理一个东西?
- sql - 将行转换为更多列
- postgresql - PITR 使用 docker 主从
- tensorflow - TensorFlow 权重的形状