2017-06-03 11 views
0

firebaseユーザを作成しようとしていますが、コードが失敗し、認証失敗メッセージが表示され続けます。 また、新しいFirebaseがアカウントに接続しているかどうかわかりませんが、Firebaseオブジェクトを作成してリンクを渡しましたが、今は違っています。私のウェブブラウザでログインして、それはそれだし、私はコードでそれのための参照を見つけることができません)チェックあなたの参照のためのコードの下なぜfirebaseユーザを作成できないのですか

@Override 
    public void onClick(View v) { 
     pass.setText(pass.getText().toString().trim()); 
     email.setText(email.getText().toString().trim()); 
     mAuth.createUserWithEmailAndPassword(email.getText().toString(), pass.getText().toString()) 
       .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         if (task.isSuccessful()) { 
          FirebaseUser user = mAuth.getCurrentUser(); 
         } else { 
          Toast.makeText(MainActivityC.this, "Authentication failed.", 
            Toast.LENGTH_SHORT).show(); 
         } 
        } 
       }); 
    } 
+0

どのようなエラーが表示されますか?あなたが作成されているかどうかを確認するfirebaseコンソールを見ましたか? –

答えて

2

...それはあなたを助けるでしょう。

private FirebaseAuth mAuth; 
    String mUserEmail = "[email protected]"; 
    String mPassword = "password"; 

    mAuth.createUserWithEmailAndPassword(mUserEmail, mPassword) 
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
      @Override 
      public void onComplete(@NonNull Task<AuthResult> task) { 

       Log.d(LOG_TAG, getString(R.string.log_message_auth_successful) + " createUserWithEmail:onComplete:" + task.isSuccessful()); 
      // if task is successful then AuthStateListener will get notified you can get user details there. 
       // if task is not successful show error 
       if (!task.isSuccessful()) { 

        try { 
         throw task.getException(); 
        } catch (FirebaseAuthUserCollisionException e) { 
         // log error here        

        } catch (FirebaseNetworkException e) { 
         // log error here 
        } catch (Exception e) { 
        // log error here   
        } 

        } else { 

       // successfully user account created 
      // now the AuthStateListener runs the onAuthStateChanged callback 

       } 
      } 

     }); 
    } 
+0

ありがとうございました –

関連する問題