I'm working on a login registration system with Firebase as backend. If the user doesn't have credentials will be redirected to registration page. Here user can enter all information. the user will be added to Firebase Authentication system and its info will be added to database eg: name, profession, email, etc... I'm using method on firebase documentation to add user user createNewUserWithEmailAndPassword() I'm getting exception
com.google.firebase.FirebaseApiNotAvailableException: API: InternalFirebaseAuth.FIREBASE_AUTH_API is not available on this device.
'com.google.firebase:firebase-auth:16.0.5'
I've added this to my gradle app
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
//firebase database
implementation 'com.google.firebase:firebase-database:16.0.4'
But the method is not registering the user in the Authentication section. Any help appreciated
package org.techgeorge.loginscreen;
public class RegisterActivity extends AppCompatActivity {
private EditText nameEditText, professionEditText, workEditText, passwordEditText;
private EditText phoneEditText, emailEditText;
private ImageView picImageView;
private CheckBox maleCheckBox, femaleCheckBox;
private Button registerButton;
private FirebaseDatabase database;
private DatabaseReference mDatabase;
private static final String USERS = "users";
private String TAG = this.getClass().getName();
private String username, fname, email, profession, phone, workplace;
private String password;
private User user;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
nameEditText = findViewById(R.id.fullname_edittext);
professionEditText = findViewById(R.id.profession_edittext);
workEditText = findViewById(R.id.workplace_edittext);
phoneEditText = findViewById(R.id.phone_edittext);
passwordEditText = findViewById(R.id.enterpass_edittext);
emailEditText = findViewById(R.id.email_edittext);
picImageView = findViewById(R.id.pic_imageview);
maleCheckBox = findViewById(R.id.male_checkbox);
femaleCheckBox = findViewById(R.id.female_checkbox);
registerButton = findViewById(R.id.register_button);
database = FirebaseDatabase.getInstance();
mDatabase = database.getReference(USERS);
mAuth = FirebaseAuth.getInstance();
registerButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//insert data into firebase database
if(emailEditText.getText().toString() != null && passwordEditText.getText().toString() != null) {
fname = nameEditText.getText().toString();
email = emailEditText.getText().toString();
phone = phoneEditText.getText().toString();
profession = professionEditText.getText().toString();
workplace = workEditText.getText().toString();
password = passwordEditText.getText().toString();
Log.d("PASSWORD", password);
user = new User(username, fname, email, profession, workplace, phone);
registerUser();
}
}
});
}
public void registerUser() {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
// addUserToDatabase(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(RegisterActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
// updateUI(null);
}
}
});
}
public void addUserToDatabase(FirebaseUser currentUser) {
}
}