2017-08-01 120 views
2

我已經使用過Firebase服務器時間了,我知道如何正確使用它。 我相信我一直在絆倒一個bug,並希望聽到一個解決方案,如果你有一個。Firebase密碼註冊不保存用戶

所以 - 我使用了Firebase Google auth,它工作正常,然後我決定使用電子郵件+密碼方法。 現在這是奇怪的部分 - 我創建一個用戶,我得到了成功的結果,但它不保存用戶 - 無法在Autherecation面板中看到它+登錄後無法與用戶登錄。

mLoginContainer.setVisibility(View.GONE); 
    mLoginProgress.setVisibility(View.VISIBLE); 
    mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
     @Override 
     public void onComplete(@NonNull Task<AuthResult> task) { 
      if(task.isSuccessful()) 
       Toast.makeText(LoginActivity.this,"",Toast.LENGTH_SHORT).show(); 
      else 
       Toast.makeText(LoginActivity.this,"",Toast.LENGTH_SHORT).show(); 
      mLoginContainer.setVisibility(View.VISIBLE); 
      mLoginProgress.setVisibility(View.GONE); 
     } 
    }); 

回答

0

您需要在Firebase控制檯上啓用電子郵件/密碼。

Click here for Firebase Auth Doc

如何啓用電子郵件/密碼登錄:

In the Firebase console, open the Auth section. 
On the Sign in method tab, enable the Email/password sign-in method and click Save. 

希望它有助於

+0

之前,正如我所說,我已經啓用它。 - 如果它沒有啓用,我會得到錯誤信息不成功。 –

0

請參閱本

希望你能加入compile 'com.google.firebase:firebase-auth:9.2.1'在gradle依賴

啓用電子郵件/密碼認證

  • 轉到您的火力面板。
  • 在左側菜單中,您會看到Auth,點擊它。 enter image description here
  • 現在點擊設置登錄方法。 enter image description here

  • 現在點擊電子郵件/密碼,啓用它,然後按保存。

對於註冊

您的註冊活動

//定義firebaseauth對象

私人FirebaseAuth firebaseAuth;

的onCreate

//初始化火力AUTH對象 firebaseAuth = FirebaseAuth.getInstance();

//用戶名和密碼的驗證成功後,[有以下)在您的設計,如果

//創建上註冊按鈕的新用戶

firebaseAuth.createUserWithEmailAndPassword(email, password) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        //checking if success 
        if(task.isSuccessful()){ 
         //display some message here 
         Toast.makeText(this,"Successfully registered",Toast.LENGTH_LONG).show(); 
        }else{ 
         //display some message here 
         Toast.makeText(this,"Registration Error",Toast.LENGTH_LONG).show(); 
        } 
        progressDialog.dismiss(); 
       } 
      }); 
  • 點擊撥打您的登記方法你得到了成功的消息。檢查您的Firebase控制檯。 enter image description here

進行登錄我已經用火力地堡

mAuth.signInWithEmailAndPassword(strUsrL,strPassL) 
          .addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
           @Override 
           public void onComplete(@NonNull Task<AuthResult> task) { 
            progressBar.setVisibility(View.GONE); 
            if(task.isSuccessful()){ 

             Toast.makeText(this, "Successfully Login", Toast.LENGTH_SHORT).show(); 
            } 

           }}) 
          .addOnFailureListener(new OnFailureListener() { 
           @Override 
           public void onFailure(@NonNull Exception e) { 

            Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); 
            Log.e("EXCEPTION",e.getLocalizedMessage().toString()); 
           } 
          }); 
+0

我正在使用最新的依賴關係11.0.2,並且已經完成了您所建議的任何事情。我獲得了成功的回調,但仍然沒有出現在面板P.S.中。 - thx嘗試 –