【问题标题】:I need to add email/password authentication with flutter and firebase我需要使用颤振和 firebase 添加电子邮件/密码身份验证
【发布时间】:2020-03-13 05:28:32
【问题描述】:
我的 Google 身份验证 工作正常正常,我需要创建另一个 signUp 方法(使用 电子邮件/和密码),那么实现这个 signUp 方法的最佳方法是什么?
我尝试创建一个用户并且它成功了。但后来我无法导航到我的其他页面!
我找不到任何好的博客文章或文档。 注意,当用户注册时,我还需要将它们添加到 firebase 数据库中。
【问题讨论】:
标签:
firebase
flutter
firebase-authentication
【解决方案1】:
试试这样的:
emailPasswordLogin(BuildContext context, String email, String password)async{
try {
AuthResult authResult = await _auth.signInWithEmailAndPassword(
email: email, password: password);
FirebaseUser user = authResult.user;
} catch (ex) {
print("Code: " + ex.code);
switch (ex.code) {
case 'ERROR_USER_NOT_FOUND':
{
await createUser(email, password, context);
}
case 'ERROR_WRONG_PASSWORD':
print("wrong password);
break;
case 'ERROR_INVALID_EMAIL':
print("invalid email")
break;
case 'ERROR_OPERATION_NOT_ALLOWED':
print("Login Method not defined")
break;
case 'ERROR_WEAK_PASSWORD':
print("weak password")
break;
default:
print('Case ${ex.message} is not yet implemented');
}
return;
}
storeData(user, context);
}
storeData(FirebaseUser user, BuildContext context) async {
_database = new FirebaseDatabase();
await _database
.reference()
.child('user')
.push().set(<dynamic, dynamic> async{
"email": user.email,
}).then((_) {
print("Transaction commited");
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => NextPage());
});
}