0

I was creating a signup page in android studio and connected it to firebase but the problem is it doesn't show me the password in Realtime database when I sign up(although the Email gets stored in authentication) this is my signup code

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.deliveryapp.Models.Users;
import com.example.deliveryapp.databinding.ActivitySignUpBinding;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;

public class SignUp extends AppCompatActivity {
    ActivitySignUpBinding binding;
    private FirebaseAuth mAuth;
    FirebaseDatabase database;
    ProgressDialog progressdialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivitySignUpBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());



        mAuth = FirebaseAuth.getInstance();
        database=FirebaseDatabase.getInstance();
        progressdialog=new ProgressDialog(SignUp.this);
        progressdialog.setTitle("Creating Account");
        progressdialog.setMessage("pls wait while we create your account");
        binding.SignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progressdialog.show();
                mAuth.createUserWithEmailAndPassword(binding.Email.getText().toString()
                        ,binding.Password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull  Task<AuthResult> task) {
                        progressdialog.dismiss();
                        if (task.isSuccessful()) {
                            Users user=new Users(binding.Username.getText().toString(),binding.Email.getText().toString(),binding.Password.getText().toString());
                            Toast.makeText(SignUp.this, "Account created", Toast.LENGTH_SHORT).show();
                            String id=task.getResult().getUser().getUid();
                            database.getReference().child("Users").child(id).setValue(user);
                        }
                        else {
                            Toast.makeText(SignUp.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }
                });
            }
        });


    }
}

and the users class is this

public Users(String username, String mail, String password) {
        this.Username = username;
        this.mail = mail;
        this.Password = password;
    }

and these are my dependencies

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-database:20.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.android.gms:play-services-location:18.0.0'

}

My app runs normally without any error being thrown in logcat

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 2
    What region did you create the Realtime Database in? If it is not in the default US region, you should specify the URL in the call to `FirebaseAuth.getInstance()`. See Alex's answer here too: https://stackoverflow.com/questions/67795058/getinstance-doesnt-work-with-other-location-than-us-central1-in-realtime-data/67802032#67802032 – Frank van Puffelen Jun 19 '21 at 15:08
  • i specified US region itself @FrankvanPuffelen – Mohammad Yusuf Jun 19 '21 at 19:38
  • 1
    So is nothing written to the database when this line executes `database.getReference().child("Users").child(id).setValue(user)`? Are there any messages showing in the logcat output when that line runs? – Frank van Puffelen Jun 19 '21 at 20:03
  • 1
    oh wait ig i found the error i had used locked database ig – Mohammad Yusuf Jun 21 '21 at 11:38

0 Answers0