将新用户添加到Firebase身份验证时,身份验证失败

时间:2019-11-18 00:13:21

标签: android firebase firebase-authentication

我正在使用Firebase作为后端的登录注册系统。如果用户没有凭据,将被重定向到注册页面。用户可以在这里输入所有信息。用户将被添加到Firebase身份验证系统,其信息将被添加到数据库,例如:姓名,专业,电子邮件等。 我正在使用Firebase文档上的方法来添加用户user createNewUserWithEmailAndPassword() 我要例外了

com.google.firebase.FirebaseApiNotAvailableException: API: InternalFirebaseAuth.FIREBASE_AUTH_API is not available on this device.
'com.google.firebase:firebase-auth:16.0.5'

我已将此添加到我的gradle应用

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'

但是该方法未在“身份验证”部分中注册用户。任何帮助表示赞赏

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) {

    }
}

0 个答案:

没有答案