英文:
com.google.firebase.auth.firebaseautInvalidUserException: there is no user corresponding to this identifier
问题
以下是您要的翻译内容:
"the issue is in case of forgotpassword reset email. I first checked whether the email is present in firebase without writing the code for sending reset mail. Then i write reset code mail it is shows Toast message while running app as invalid user exception. No such Record."
"问题出在忘记密码重置邮件的情况下。我首先检查了Firebase中是否存在电子邮件,而不写发送重置邮件的代码。然后,当运行应用程序时,我编写了重置代码邮件,它显示Toast消息,作为无效用户异常。没有这样的记录。"
请注意,一些代码部分和符号(如<和>)无法直接翻译,因为它们是编程代码的一部分。
英文:
the issue is in case of forgotpassword reset email. I first checked whether the email is present in firebase without writing the code for sending reset mail.Then i write reset code mail it is shows Toastmessage while running app as invaliduserexception.No such Record.
package com.example.loginapp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot_password);
mAuth=FirebaseAuth.getInstance();
forgotenteredmail=findViewById(R.id.forgotenteredmail);
forgotnextbutton=findViewById(R.id.forgotnextbutton);
mAuth=FirebaseAuth.getInstance();
forgotnextbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!validateemail() )
{
return;
}
else
{
isUser();
}
}
});
}
private Boolean validateemail ()
{
String val=forgotenteredmail.getEditText().getText().toString();
if(val.isEmpty()){
forgotenteredmail.setError("The Field Cannot be Empty");
return false;
}
else{
forgotenteredmail.setError(null);
forgotenteredmail.setErrorEnabled(false);
return true;
}
}
private void isUser() {
email = forgotenteredmail.getEditText().getText().toString().trim();
rootnode = FirebaseDatabase.getInstance();
reference = rootnode.getReference("users");
final Query checkuser = reference.orderByChild("email").equalTo(email);
checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
forgotenteredmail.setError(null);
forgotenteredmail.setErrorEnabled(false);
resetUserPassword(email);
} else {
forgotenteredmail.setError("User does not Exist");
forgotenteredmail.requestFocus();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public void resetUserPassword(String email){
final ProgressDialog progressDialog = new ProgressDialog(forgotPassword.this);
progressDialog.setMessage("verifying..");
progressDialog.show();
mAuth.sendPasswordResetEmail(email)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Reset password instructions has sent to your email",
Toast.LENGTH_SHORT).show();
}else{
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Email don't exist", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
});}
}
the problem occurs when sending reset mail
firebase database
- **-appname**
**-users**
-username
-name:
-email
-username[enter image description here][1]
-passs
-phone
-username
-name
{
"rules": {
".read": true,
".write": true,
"users":{
".indexOn":"email"
}
}
}
答案1
得分: 0
那条消息来自于:
reference=rootnode.getReference("users");
final Query checkuser=reference.orderByChild("email").equalTo(email);
checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
...
错误消息相当明确关于问题和解决方案:
> 使用未指定的索引。您的数据将在客户端上下载和过滤。考虑在“users”中添加“".indexOn": "email"”到您的安全性和Firebase数据库规则,以获得更好的性能。
要解决这个问题,您需要根据[索引数据](https://firebase.google.com/docs/database/security/indexing-data)文档中的描述,在数据库的安全规则中添加索引。
类似于:
{
"rules": {
"users": {
".indexOn": "email"
}
}
}
---
**更新**:由于您在尝试使此工作时遇到困难,我在此jsbin中创建了一个示例:https://jsbin.com/kevafej/edit?js,console
节点`63097781`下的数据是:
{
"users" : {
"abc" : {
"email" : "abc@acme.org"
},
"def" : {
"email" : "def@acme.org"
}
}
}
相关代码:
```javascript
var ref = firebase.database().ref("63097781");
ref.child('users')
.orderByChild('email')
.equalTo('abc@acme.org')
.once('value')
.then(function(results) {
results.forEach((snapshot)=>{
console.log(snapshot.val());
})
})
如果我为节点63097781
设置规则如下:
"63097781": {
".read": true
}
我将得到正确的节点({ email: "abc@acme.org" }
),但会带有以下警告:
> FIREBASE警告:使用未指定的索引。您的数据将在客户端上下载并过滤。请考虑在/63097781/users添加“.indexOn”:“email”到您的安全规则,以获得更好的性能。
然后,如果我将规则更改为(添加警告消息中所说的内容):
"63097781": {
".read": true,
"users": {
".indexOn": "email"
}
}
在这些规则下,我们将获得相同的结果,但不会出现警告。
<details>
<summary>英文:</summary>
That message comes from:
reference=rootnode.getReference("users");
final Query checkuser=reference.orderByChild("email").equalTo(email);
checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
...
The error message is quite explicit about the problem and solution:
> Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "email"' at users to your security and Firebase Database rules for better performance
To solve the problem you need to add an index to your database's security rules as described in the documentation on [indexing your data](https://firebase.google.com/docs/database/security/indexing-data).
Something like:
{
"rules": {
"users": {
".indexOn": "email"
}
}
}
---
**Update**: since you're having trouble getting this to work, I created an example in this jsbin: https://jsbin.com/kevafej/edit?js,console
The data under node `63097781` is:
{
"users" : {
"abc" : {
"email" : "abc@acme.org"
},
"def" : {
"email" : "def@acme.org"
}
}
}
The relevant code:
var ref = firebase.database().ref("63097781");
ref.child('users')
.orderByChild('email')
.equalTo('abc@acme.org')
.once('value')
.then(function(results) {
results.forEach((snapshot)=>{
console.log(snapshot.val());
})
})
If I set the rules for node `63097781` to:
"63097781": {
".read": true
}
I get the correct node (`{ email: "abc@acme.org" }`), but with this warning:
> FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "email" at /63097781/users to your security rules for better performance.
If I then change the rules to (adding exactly what is said in the warning message):
"63097781": {
".read": true,
"users": {
".indexOn": "email"
}
}
With these rules we get the same results, but without the warning.
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论