Firebase:通过云功能检查用户电子邮件是否已验证

Moh*_*eja 5 firebase firebase-authentication google-cloud-functions

有没有办法检查电子邮件是否通过云功能验证,即如果我有用户的 uid,我可以检查该特定用户的电子邮件是否经过验证。在我的用例中,我需要确保在执行交易之前验证电子邮件。我想检查服务器端

云函数示例:

exports.executeTransaction = functions.https.onCall((data,context)=>{ 

const userid = context.auth.uid 

//Check if email is verified
//I want to use context variable to somehow extract whether email is verified. Is there a way to do it ?
//Execute Transaction if email is verified
})
Run Code Online (Sandbox Code Playgroud)

Moh*_*eja 2

没关系,我设法弄清楚了。

有类似问题的人请参阅以下内容:

exports.executeTransaction = functions.https.onCall((data,context)=>{ 
const userid = context.auth.uid 
//Check if email is verified
return admin.auth().getUser(context.auth.uid).then(user => {
//Check if email verified
  if(user.emailVerified)
  {
return "Verified"
}
else{
console.log("User Email not verified")
return "Not Verified"
}
}).catch(function(err){
  console.log(err)
  throw new functions.https.HttpsError('Error Validating', err.message, err)
})
})
Run Code Online (Sandbox Code Playgroud)