2017-07-18 77 views
3

有沒有使用「createUserWithEmailAndPassword」的方法?我問的原因是因爲我希望在用戶登錄之前驗證電子郵件。當新用戶創建它自動登錄在JavaScript的firebase中

firebase.auth().createUserWithEmailAndPassword(mailId, password).then(function(data){ 
      console.log("user created"); 
firebase.auth().currentUser.sendEmailVerification().then(function() { 
      console.log("verification email send"); 
      }) 
     }).catch(function(error) { 
    console.log("error.message"); 
}) 

此代碼自動登錄用戶並將驗證郵件發送給用戶。有沒有什麼辦法比signIn驗證電子郵件。

+0

請格式化正確 – eddyP23

+0

最簡單的解決辦法是調用'signOut'在'then'處理程序(根據[文檔](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword),成功創建帳戶後,用戶將始終登錄) – UnholySheep

回答

1

您無法阻止用戶使用未經驗證的電子郵件地址登錄。這不僅僅是Firebase身份驗證的工作方式:如果用戶知道登錄所需的憑據,他們已證明他們是誰並登錄。

您可以做的是阻止他們訪問特定資源,例如Firebase數據庫。事實上,我的回答這個問題,說明如何做到這一點(用戶從特定電子郵件域和限制訪問):How do I lock down Firebase Database to any user from a specific (email) domain?

相關問題