Firestore数据库注册失败,权限被拒绝,但实际上已成功注册。

huangapple go评论65阅读模式
英文:

Firestore Database Registration Failed Permission Denied But Actually Successfully Registers

问题

以下是翻译好的部分:

private void showREGISTERnew() {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("注册");
    dialog.setMessage("请使用电子邮件进行注册。");

    LayoutInflater inflater = LayoutInflater.from(this);
    View layout_login = inflater.inflate(R.layout.layout_login, null);

    final MaterialEditText editEmail = layout_login.findViewById(R.id.editEmail);
    final MaterialEditText editPassword = layout_login.findViewById(R.id.editPassword);

    dialog.setView(layout_login);

    // 设置按钮
    dialog.setPositiveButton("注册", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();

            // 验证检查

            if(TextUtils.isEmpty(editEmail.getText().toString())){
                Snackbar.make(rootLayout, "请输入电子邮件地址", Snackbar.LENGTH_SHORT)
                        .show();
                return;
            }

            if(TextUtils.isEmpty(editPassword.getText().toString())){
                Snackbar.make(rootLayout, "请输入密码", Snackbar.LENGTH_SHORT)
                        .show();
                return;
            }

            if(editPassword.getText().toString().length() < 6){
                Snackbar.make(rootLayout, "密码太短。", Snackbar.LENGTH_SHORT)
                        .show();
                return;
            }

            // 注册新用户

            auth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPassword.getText().toString())
                    .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                        @Override
                        public void onSuccess(AuthResult authResult) {
                            // 将用户保存到数据库
                            User user = new User();
                            user.setEmail(editEmail.getText().toString());

                            // 设置用户电话
                            // 设置用户姓名

                            user.setPassword(editPassword.getText().toString());
                            // 使用电子邮件作为键
                            users.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                    .setValue(user)
                                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                                        @Override
                                        public void onSuccess(Void aVoid) {
                                            Snackbar.make(rootLayout, "您已成功注册。", Snackbar.LENGTH_SHORT)
                                                    .show();
                                        }
                                    })
                                    .addOnFailureListener(new OnFailureListener() {
                                        @Override
                                        public void onFailure(@NonNull Exception e) {
                                            Snackbar.make(rootLayout, "注册失败。" + e.getMessage(), Snackbar.LENGTH_SHORT)
                                                    .show();
                                        }
                                    });
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Snackbar.make(rootLayout, "注册失败。" + e.getMessage(), Snackbar.LENGTH_SHORT)
                                    .show();
                        }
                    });
        }
    });
}
英文:

So I am having a rather ambiguous issue with my database. Everything was working fine and anytime I would register or somebody would register on my app, it would make the messasge "Registration Successful!" pop up.

I have been updating my code daily and working on changing things in the app and around the database. Today while registering a test user, I got this message - Firestore数据库注册失败,权限被拒绝,但实际上已成功注册。

It claims that registration failed, but the account was successfully registered. And I have tested this with 3 more accounts. Same message - registration, however, is actually successful and the user can log in with his details.

I have not coded this exception. I have coded exceptions such as password too short, registration failed, no internet, etc, but never have I created a Permission check. I think the Permission Denied comes from the +e.getMessage()? Could I have changed something inside the firestorm database rules?

This is my code:

    private void showREGISTERnew() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(&quot;REGISTER&quot;);
dialog.setMessage(&quot;Please use email to register.&quot;);
LayoutInflater inflater = LayoutInflater.from(this);
View layout_login = inflater.inflate(R.layout.layout_login, null);
final MaterialEditText editEmail = layout_login.findViewById(R.id.editEmail);
final MaterialEditText editPassword = layout_login.findViewById(R.id.editPassword);
dialog.setView(layout_login);
//set btton
dialog.setPositiveButton(&quot;REGISTER&quot;, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//check validation
if(TextUtils.isEmpty(editEmail.getText().toString())){
Snackbar.make(rootLayout, &quot;Please enter email address&quot;, Snackbar.LENGTH_SHORT)
.show();
return;
}
if(TextUtils.isEmpty(editPassword.getText().toString())){
Snackbar.make(rootLayout, &quot;Please enter your password&quot;, Snackbar.LENGTH_SHORT)
.show();
return;
}
if(editPassword.getText().toString().length() &lt; 6){
Snackbar.make(rootLayout, &quot;Password too short.&quot;, Snackbar.LENGTH_SHORT)
.show();
return;
}
//reg new user
auth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener&lt;AuthResult&gt;() {
@Override
public void onSuccess(AuthResult authResult) {
//save user to db
User user = new User();
user.setEmail(editEmail.getText().toString());
//user setphone
//user setname
user.setPassword(editPassword.getText().toString());
//use email to key
users.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user)
.addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
@Override
public void onSuccess(Void aVoid) {
Snackbar.make(rootLayout, &quot;You have registered successfully.&quot;, Snackbar.LENGTH_SHORT)
.show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, &quot;Registration failed.&quot;+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, &quot;Registration failed.&quot;+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
});

答案1

得分: 0

我实际上实现了两个数据库。一个将保存用户基础,另一个将保存价格和位置数据。

然而,我忘记了在一段时间后,读写权限会自动设置为 false。

在几周前收到通知时,我在主数据库上将读写权限改回为 true,但忘记了第二个数据库。

我检查了第二个数据库,权限被设置为 false,导致我注册失败,权限被拒绝,尽管我可以注册。

将它们改回 true 后,应用程序运行正常。

英文:

I actually implemented two databases. One that will hold the userbase ad one that will hold price and location data.

However, I forgot that after a certain period of time, read and write permissions will be automatically set to false.

When I got the notification weeks ago, I changed back the read and write permissions to true on the main database, but forgot about the second one.

I checked the second one and the permissions were set to false, thus giving me registration failed, permission denied even though I could register.

After changing them back to true, application works flawlessly.

huangapple
  • 本文由 发表于 2020年4月10日 22:27:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/61142397.html
匿名

发表评论

匿名网友

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

确定