com.google.firebase.auth.firebaseauthInvalidUserException: 没有与此标识符对应的用户。

huangapple 未分类评论67阅读模式
英文:

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.

  1. package com.example.loginapp;
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_forgot_password);
  6. mAuth=FirebaseAuth.getInstance();
  7. forgotenteredmail=findViewById(R.id.forgotenteredmail);
  8. forgotnextbutton=findViewById(R.id.forgotnextbutton);
  9. mAuth=FirebaseAuth.getInstance();
  10. forgotnextbutton.setOnClickListener(new View.OnClickListener() {
  11. @Override
  12. public void onClick(View v) {
  13. if(!validateemail() )
  14. {
  15. return;
  16. }
  17. else
  18. {
  19. isUser();
  20. }
  21. }
  22. });
  23. }
  24. private Boolean validateemail ()
  25. {
  26. String val=forgotenteredmail.getEditText().getText().toString();
  27. if(val.isEmpty()){
  28. forgotenteredmail.setError(&quot;The Field Cannot be Empty&quot;);
  29. return false;
  30. }
  31. else{
  32. forgotenteredmail.setError(null);
  33. forgotenteredmail.setErrorEnabled(false);
  34. return true;
  35. }
  36. }
  37. private void isUser() {
  38. email = forgotenteredmail.getEditText().getText().toString().trim();
  39. rootnode = FirebaseDatabase.getInstance();
  40. reference = rootnode.getReference(&quot;users&quot;);
  41. final Query checkuser = reference.orderByChild(&quot;email&quot;).equalTo(email);
  42. checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
  43. @Override
  44. public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  45. if (dataSnapshot.exists()) {
  46. forgotenteredmail.setError(null);
  47. forgotenteredmail.setErrorEnabled(false);
  48. resetUserPassword(email);
  49. } else {
  50. forgotenteredmail.setError(&quot;User does not Exist&quot;);
  51. forgotenteredmail.requestFocus();
  52. }
  53. }
  54. @Override
  55. public void onCancelled(@NonNull DatabaseError databaseError) {
  56. }
  57. });
  58. }
  59. public void resetUserPassword(String email){
  60. final ProgressDialog progressDialog = new ProgressDialog(forgotPassword.this);
  61. progressDialog.setMessage(&quot;verifying..&quot;);
  62. progressDialog.show();
  63. mAuth.sendPasswordResetEmail(email)
  64. .addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
  65. @Override
  66. public void onComplete(@NonNull Task&lt;Void&gt; task) {
  67. if(task.isSuccessful()){
  68. progressDialog.dismiss();
  69. Toast.makeText(getApplicationContext(), &quot;Reset password instructions has sent to your email&quot;,
  70. Toast.LENGTH_SHORT).show();
  71. }else{
  72. progressDialog.dismiss();
  73. Toast.makeText(getApplicationContext(),
  74. &quot;Email don&#39;t exist&quot;, Toast.LENGTH_SHORT).show();
  75. }
  76. }
  77. }).addOnFailureListener(new OnFailureListener() {
  78. @Override
  79. public void onFailure(@NonNull Exception e) {
  80. progressDialog.dismiss();
  81. Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
  82. }
  83. });}

}

the problem occurs when sending reset mail

firebase database

  1. - **-appname**
  2. **-users**
  3. -username
  4. -name:
  5. -email
  6. -username[enter image description here][1]
  7. -passs
  8. -phone
  9. -username
  10. -name
  1. {
  2. &quot;rules&quot;: {
  3. &quot;.read&quot;: true,
  4. &quot;.write&quot;: true,
  5. &quot;users&quot;:{
  6. &quot;.indexOn&quot;:&quot;email&quot;
  7. }
  8. }
  9. }

com.google.firebase.auth.firebaseauthInvalidUserException: 没有与此标识符对应的用户。

答案1

得分: 0

  1. 那条消息来自于:
  2. reference=rootnode.getReference("users");
  3. final Query checkuser=reference.orderByChild("email").equalTo(email);
  4. checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
  5. ...
  6. 错误消息相当明确关于问题和解决方案:
  7. &gt; 使用未指定的索引。您的数据将在客户端上下载和过滤。考虑在“users”中添加“&quot;.indexOn&quot;: &quot;email&quot;”到您的安全性和Firebase数据库规则,以获得更好的性能。
  8. 要解决这个问题,您需要根据[索引数据](https://firebase.google.com/docs/database/security/indexing-data)文档中的描述,在数据库的安全规则中添加索引。
  9. 类似于:

{
"rules": {
"users": {
".indexOn": "email"
}
}
}

  1. ---
  2. **更新**:由于您在尝试使此工作时遇到困难,我在此jsbin中创建了一个示例:https://jsbin.com/kevafej/edit?js,console
  3. 节点`63097781`下的数据是:

{
"users" : {
"abc" : {
"email" : "abc@acme.org"
},
"def" : {
"email" : "def@acme.org"
}
}
}

  1. 相关代码:
  2. ```javascript
  3. var ref = firebase.database().ref("63097781");
  4. ref.child('users')
  5. .orderByChild('email')
  6. .equalTo('abc@acme.org')
  7. .once('value')
  8. .then(function(results) {
  9. results.forEach((snapshot)=>{
  10. console.log(snapshot.val());
  11. })
  12. })

如果我为节点63097781设置规则如下:

  1. "63097781": {
  2. ".read": true
  3. }

我将得到正确的节点({ email: "abc@acme.org" }),但会带有以下警告:

> FIREBASE警告:使用未指定的索引。您的数据将在客户端上下载并过滤。请考虑在/63097781/users添加“.indexOn”:“email”到您的安全规则,以获得更好的性能。

然后,如果我将规则更改为(添加警告消息中所说的内容):

  1. "63097781": {
  2. ".read": true,
  3. "users": {
  4. ".indexOn": "email"
  5. }
  6. }

在这些规则下,我们将获得相同的结果,但不会出现警告。

  1. <details>
  2. <summary>英文:</summary>
  3. That message comes from:
  4. reference=rootnode.getReference(&quot;users&quot;);
  5. final Query checkuser=reference.orderByChild(&quot;email&quot;).equalTo(email);
  6. checkuser.addListenerForSingleValueEvent(new ValueEventListener() {
  7. ...
  8. The error message is quite explicit about the problem and solution:
  9. &gt; Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding &#39;&quot;.indexOn&quot;: &quot;email&quot;&#39; at users to your security and Firebase Database rules for better performance
  10. To solve the problem you need to add an index to your database&#39;s security rules as described in the documentation on [indexing your data](https://firebase.google.com/docs/database/security/indexing-data).
  11. Something like:

{
"rules": {
"users": {
".indexOn": "email"
}
}
}

  1. ---
  2. **Update**: since you&#39;re having trouble getting this to work, I created an example in this jsbin: https://jsbin.com/kevafej/edit?js,console
  3. The data under node `63097781` is:

{
"users" : {
"abc" : {
"email" : "abc@acme.org"
},
"def" : {
"email" : "def@acme.org"
}
}
}

  1. 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());
})
})

  1. If I set the rules for node `63097781` to:

"63097781": {
".read": true
}

  1. I get the correct node (`{ email: &quot;abc@acme.org&quot; }`), but with this warning:
  2. &gt; FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding &quot;.indexOn&quot;: &quot;email&quot; at /63097781/users to your security rules for better performance.
  3. If I then change the rules to (adding exactly what is said in the warning message):

"63097781": {
".read": true,
"users": {
".indexOn": "email"
}
}

  1. With these rules we get the same results, but without the warning.
  2. </details>

huangapple
  • 本文由 发表于 2020年7月26日 16:21:29
  • 转载请务必保留本文链接:https://java.coder-hub.com/63097781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定