无法使用firebase auth模块注册

Ash*_*Jha 5 android firebase firebase-authentication

我们的要求

在Android上使用Firebase SDK使用电子邮件/密码注册

问题

onComplete()方法未被调用.不会抛出任何错误/异常.注意:我们已在Firebase控制台上启用了电子邮件/密码提供程序

请找到以下代码 -

public void onClick(View v) {
        try {
            if (v == saveView) {
                String email = emailView.getText().toString();
                String password = passwordView.getText().toString();
                if (validate(email, password)) {

                    mAuth.createUserWithEmailAndPassword(email, password)
                            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                                @Override
                                public void onComplete(@NonNull Task<AuthResult> task) {
                                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                                    // If sign in fails, display a message to the user. If sign in succeeds
                                    // the auth state listener will be notified and logic to handle the
                                    // signed in user can be handled in the listener.
                                    if (!task.isSuccessful()) {
                                        Toast.makeText(UserRegisterActivity.this, "Authentication failed.",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                }
            }
        }catch (Exception e) {
            Log.d("BIG", e.getStackTrace().toString());
        }
    }

 private boolean validate(String email , String password){
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

Van*_*hed 0

试试这个,这对我有用,也许对你有帮助

 firebase.createUser(etEmail.getText().toString(), etPassword.getText().toString(), new Firebase.ValueResultHandler<Map<String, Object>>() {
                @Override
                public void onSuccess(Map<String, Object> result) {


                    System.out.println("Successfully created user account with uid: " + result.get("uid"));

                }
                @Override
                public void onError(FirebaseError firebaseError) {
                    // there was an error

                    String errorMessage = firebaseError.getMessage();

                    Toast.makeText(RegisterActivity.this, ""+errorMessage, Toast.LENGTH_SHORT).show();
                }


            });
Run Code Online (Sandbox Code Playgroud)

登录

 firebase.authWithPassword(etEmail.getText().toString(), etPassword.getText().toString(), new Firebase.AuthResultHandler() {
                @Override
                public void onAuthenticated(AuthData authData) {

                    Log.e(TAG, "User Authenticated");

                    System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());

                }

                @Override
                public void onAuthenticationError(FirebaseError firebaseError) {
                    switch (firebaseError.getCode()) {
                        case FirebaseError.USER_DOES_NOT_EXIST:
                            // handle a non existing user

                            Log.e(TAG, "User Does Not Exist");
                            break;
                        case FirebaseError.INVALID_PASSWORD:
                            // handle an invalid password
                            Log.e(TAG, "Invalid Password");
                            break;
                        default:
                            // handle other errors
                            break;
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)