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 -
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("REGISTER");
dialog.setMessage("Please use email to register.");
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("REGISTER", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//check validation
if(TextUtils.isEmpty(editEmail.getText().toString())){
Snackbar.make(rootLayout, "Please enter email address", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(TextUtils.isEmpty(editPassword.getText().toString())){
Snackbar.make(rootLayout, "Please enter your password", Snackbar.LENGTH_SHORT)
.show();
return;
}
if(editPassword.getText().toString().length() < 6){
Snackbar.make(rootLayout, "Password too short.", Snackbar.LENGTH_SHORT)
.show();
return;
}
//reg new user
auth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@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<Void>() {
@Override
public void onSuccess(Void aVoid) {
Snackbar.make(rootLayout, "You have registered successfully.", Snackbar.LENGTH_SHORT)
.show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "Registration failed."+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Snackbar.make(rootLayout, "Registration failed."+e.getMessage(), Snackbar.LENGTH_SHORT)
.show();
}
});
}
});
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.