无法使用firebase auth模块注册

时间:2016-05-31 13:23:57

标签: 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;
    }

2 个答案:

答案 0 :(得分: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();
                }


            });

登录

 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;
                    }
                }
            });

答案 1 :(得分:0)

对于 Firebase旧API 试试此

ruby C:/cmock/lib/cmock.rb --mock_path="C:/unittest/src/mocks" --mock_prefix="mock_" --includes="qep.h, sp_core.h, sp_osapi.h" qf.h
WARNING: :includes should be an array.

这是创建帐户

fbRoot.authWithPassword("email", "pasw", new Firebase.AuthResultHandler() {
            @Override
            public void onAuthenticated(AuthData authData) {
                Toast.makeText(MainActivity.this, "User ID: " + authData.getUid() + ", Provider: " + authData.getProvider(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onAuthenticationError(FirebaseError firebaseError) {

            }
        });