【发布时间】:2019-09-14 15:39:45
【问题描述】:
我正在编写一个 Firebase 函数来在注册我的网络应用程序后验证用户的电子邮件,但是即使在检查注册时创建的唯一哈希与我的函数 URL 中的查询匹配之后,该函数仍然返回 false它应该返回 true,即找到用户
在 async/await 和 Promise 方面,我是一个相对新手,我尝试在代码中的不同位置使用它们,但没有任何效果。
exports.verifyMail = functions.https.onRequest((req, res) => {
cors(req, res, () => {
const hash = req.query.hash;
const pendingUserKey = req.query.pendingUserKey;
var pendingUser;
admin
.database()
.ref('pending/' + pendingUserKey)
.once('value', snapshot => {
pendingUser = snapshot.val();
})
.then(function() {
console.log(pendingUser);
console.log(pendingUser.hash);
console.log(hash);
if (pendingUser.hash === hash) {
return res.send('User hash matches');
} else {
return res.send('User not found');
}
})
.catch(error => {
console.log(error);
});
});
});
预期结果是已在数据库中找到用户。 Firebase 控制台日志确认pendingUser.hash 和哈希值相等,但该函数每次仍返回“未找到用户”。
【问题讨论】:
标签: javascript firebase-realtime-database google-cloud-functions