First time using Firebase and I also haven't coded in about 5 years, so excuse the rust. I'm just attempting to make a registration with Firebase.
Authentication for email/password has been setup on the real-time database, but whenever I attempt to enter a valid email and password, no matter what I get an error. On both emulator and my S21. Any help to this noob much appreciated:)
public class DriverLoginActivity extends AppCompatActivity {
private EditText mEmail, mPassword;
private Button mLogin, mRegister;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthListener;
mEmail = (EditText) findViewById(R.id.email);
mPassword = (EditText) findViewById(R.id.password);
mLogin = (Button) findViewById(R.id.login);
mRegister = (Button) findViewById(R.id.register);
mRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String email = mEmail.getText().toString();
final String password = mPassword.getText().toString();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(!task.isSuccessful())
{
Toast.makeText(DriverLoginActivity.this, "Error - Please check username and password requirements", Toast.LENGTH_SHORT).show();
}
else
{
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(user_id);
current_user_db.setValue(true);
}
}
});
}
});
LOGCAT: 2021-12-14 12:49:35.427 16103-16103/com.example.hippotaxi D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10156; state: ENABLED 2021-12-14 12:49:40.439 16103-16131/com.example.hippotaxi W/System: Ignoring header X-Firebase-Locale because its value was null.
You should get the current instance of FirebaseAuth before call the createUserWithEmailAndPassword
On your Activity's OnCreate method, add this line:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Your code if need...
mAuth = FirebaseAuth.getInstance();
// Your code if need...
}
And as always, check if your dependencies are up to date
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.