我正在將Android應用程序從舊版本遷移到新的Firebase平臺。如果給定未知的電子郵件字符串,我似乎無法使sendPasswordResetEmail按照電子郵件/密碼身份驗證的文檔工作。Firebase sendPasswordResetEmail似乎無法與firebase-auth正常工作:9.0.2
文檔說:
public Task sendPasswordResetEmail (String email)
Triggers the Firebase Authentication backend to send a password-reset email to the given email address, which must correspond to an existing user of your app.
Exceptions:
FirebaseAuthInvalidUserException thrown if there is no user corresponding to the given email address Returns Task to track completion of the sending operation
這裏是我的PW復位方法:
// firebase password reset
private void requestPwReset() {
String email = mEmailView.getText().toString();
Log.d(TAG, "sending pw reset request for: " + email);
try {
Task<Void> task = mAuth.sendPasswordResetEmail(email);
Log.d("TAG", "result: " + (task.isSuccessful() == true)); // NEVER SUCCEEDS, EVEN WITH VALID EMAIL ADDRESS
} catch(FirebaseAuthInvalidUserException e) { //COMPILE ERROR HERE!
Log.d(TAG, "exception: " + e.toString());
}
}
調用此方法導致此編譯時錯誤(該IDE也標誌):
LoginActivity.java:117: error: exception FirebaseAuthInvalidUserException is never thrown in body of corresponding try statement } catch(FirebaseAuthInvalidUserException e) {
如果我省略了try-catch代碼,那麼該方法會編譯,但返回的任務永遠不會成功,即使已知od電子郵件地址。
好消息是,Firebase最終會將重置設置發送到正確的地址,但我想知道爲什麼sendPasswordResetEmail在給出未知的用戶電子郵件或給定有效的電子郵件時不會拋出記錄的異常。
我在5月18日的發行說明中看到,此功能存在iOS問題。