firebase - Firebase:通过云功能检查用户电子邮件是否经过验证
问题描述
有没有办法检查电子邮件是否通过云功能验证,即如果我有用户的 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
})
解决方案
根据文档,上下文包括decodedIdToken
,它已经包含一个email_verified
字段。
因此,您需要做的就是:
exports.executeTransaction = functions.https.onCall((data, context) => {
const { token } = context.auth;
if (!token.firebase.email_verified)
throw new functions.https.HttpsError(
"failed-precondition",
"The function must be called while authenticated."
);
// ...do stuff
})
https://firebase.google.com/docs/reference/functions/functions.https#.CallableContext
https://firebase.google.com/docs/reference/admin/node/admin.auth.DecodedIdToken#email_verified
推荐阅读
- swift - SwiftUI Picker 可以返回对象 ID 吗?
- cassandra - Scylla/Cassandra:没有 TTL 的时间序列数据的压缩策略
- android - RxJava如何创建一个以不同延迟执行多个作业的间隔?
- python-requests - 使用 python 的 requests 库发出 get 请求
- directus - Directus 自定义界面 - 重新加载集合条目数据
- python - 每个视图的自定义导航栏
- c++ - 我想让用户选择一个他们想要保留的数字并放入一个数组中。并将它们放入单独的索引中
- elasticsearch - Opendistro for Elasticsearch - ISM 未触发作业
- python - 使用 PyTorch 耗尽 GPU 内存
- python - 如何仅使用一个 dockerfile 将 Flask API 与 mongo 加入?