2017-03-18 30 views
1

我想在用戶創建後發送驗證郵件。由於Firebase本身無法使用,我正在嘗試使用雲端功能。如何使用Firebase Cloud功能創建用戶後發送電子郵件驗證?

我真的不能找到很多關於它的文檔。我試圖做到目前爲止:

exports.sendEmailVerification = functions.auth.user().onCreate(event => { 
    return user.sendEmailVerification() 
}); 

但我得到的錯誤,用戶沒有定義。

如何創建此功能?

謝謝!

+0

您是否找到解決方案? – wonsuc

+0

不,我切換到couchbase – Davide

回答

5

由於@Alexander回答和評論,只有登錄用戶可以請求驗證電子郵件發送。目前無法通過Cloud Functions使用的Admin SDK執行此操作,因爲這很容易被濫用。

如果您想這種能力被添加到管理員SDK,我建議你file a feature request

在此期間,你可以使用雲功能實現自己的電子郵件驗證流程。一旦您從用戶處取回驗證碼,您可以使用Admin SDK將其emailVerified屬性設置爲true。見this section of the Firebase documentation for an example

+0

謝謝。這使得Firebase在生產階段非常無用。我將提交功能請求,但我也會評估Firebase的替代方案。 – Davide

1

首先查看由火力地堡here的文檔。

作爲註冊階段完成並導致成功,觸發以下功能異步:

private void sendVerification() { 
      FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 
      user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() { 
       @Override 
       public void onComplete(@NonNull Task<Void> task) { 
        if (task.isSuccessful()) { 
         system.print.out("Verification Email sent Champion") 
          } 
         } 
       }); 
} 

用戶現在將提供與驗證電子郵件。點擊超級鏈接後,用戶將通過Firebase的項目服務器進行驗證。

enter image description here

你如何確定用戶是否也驗證他們的電子郵件?

private void checkEmail() { 

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 

    if (user.isEmailVerified()) { 
      // email verified ... 
    } else { 
     // error : email not verified ... 
    } 
} 

可悲的是,你可能不自定義驗證電子郵件的內容/體(我一直在用大量火力地堡對應於提供替代性少可怕尋找模板)。您可以更改標題或消息發件人ID,但這就是它的全部內容。

除非你重新鏈接與自己支持的Web應用程序。 Here

+0

謝謝,但我用Firebase雲說,而不是與Android。我感到非常失望的是,它是發送驗證郵件的客戶端本身。它應該來自後端。 – Davide

+0

您希望驗證郵件在用戶註冊正確的同時被觸發併發送? – Alexander

+0

沒問題,如果可能的話...... – Davide

相關問題