2016-10-19 2 views
2

Firebase의 인증 서비스를 사용하고 있습니다 만 인증/전자 메일 이미 사용 중이거나 인증/유효하지 않은 전자 메일과 같은 createUserWithEmailAndPassword()의 오류 코드를 처리하는 방법을 모르지만, 여기에 오류 목록을 https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPasswordFirebaseAuth 예외를 처리하는 방법

public void register(View target){ 
     EditText email = (EditText) findViewById(R.id.editTextName); 
     EditText pass = (EditText) findViewById(R.id.editTextPass); 
     Log.d("email",email.getText().toString()); 
     Log.d("pass",pass.getText().toString()); 
     auth.createUserWithEmailAndPassword(email.getText().toString(),pass.getText().toString()) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>(){ 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        if(task.isSuccessful()){ 
         Toast.makeText(RegistroActivity.this, "success", 
           Toast.LENGTH_SHORT).show(); 
        }else{ 
         Toast.makeText(RegistroActivity.this, "fail", 
           Toast.LENGTH_SHORT).show(); 
        } 

       } 
      }); 

    } 

답변

1
FirebaseAuth.getInstance().createUserWithEmailAndPassword("EMAIL", "PASSWORD") 
    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
     @Override 
     public void onComplete(@NonNull Task<AuthResult> task) { 
      if (!task.isSuccessful()) { 
       if (task.getException() instanceof FirebaseAuthUserCollisionException) { 
       // thrown if there already exists an account with the given email address 
       } else if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { 
       // thrown if the email address is malformed 
       } else if (task.getException instanceof FirebaseAuthWeakPasswordException) { 
       // thrown if the password is not strong enough 
       } 
      } 
     } 
    }); 
+0

PS를 볼 수 있습니다 FirebaseAuthUserCollisionException에 대해 사용자의 중포 기지 콘솔에서 선택할 수 있습니다 여부를 더 등록 할 수 있습니다 이메일로 계정이. 인증 -> 방법 -> 고급 –

관련 문제