【发布时间】:2020-01-10 13:52:30
【问题描述】:
我正在尝试通过在注册时通过邮件发送的链接来验证我的用户电子邮件地址。 当用户注册时,我在临时表中创建了一个指向其 uid 的引用,并发送一封带有链接的邮件以激活他的帐户。 这个链接调用我的firebase云函数,我检查参数中传递的值是否存在于临时表中,如果存在,我激活关联的帐户,然后删除临时表上的记录。
到目前为止我所拥有的:
exports.confirmMail = (data) => {
return admin.database().ref(`/Email-Verifications/${data.uid}`).once('value')
.then((snapshot) => {
let uid = snapshot.val().userId;
return new Promise((resolve, reject) => {
admin.auth().updateUser(uid, { emailVerified : true })
.then(()=>{
admin.database().ref(`/Email-Verifications/${data.uid}`).remove()
.then(()=>{
console.log('email verified');
return 'Ok';
})
.catch(()=>{
console.log(error);
return error;
})
})
})
.catch((error)=>{
console.log(error);
return error;
})
})
.catch((error)=>{
console.log(error);
return error;
})
}
这有效(根据 firebase 控制台中的日志),但在我的前端我得到一个空对象,所以无法知道该过程是否真的有效。
我迷失了承诺返回,我不得不通过return new Promise (...) 更改 .then 以消除我遇到的“超出最大调用堆栈大小”错误。
在前面我称之为:
verifMail(uid){
console.log('fetching on uid : ' + uid);
var func = firebase.functions().httpsCallable('confirmMail');
console.log(func);
func({ uid : uid })
.then((responseValue)=> {
console.log(responseValue);
this.setState({ isProcessDone : true});
})
.catch((error) => {
console.error(error);
});
}
【问题讨论】:
-
所以在 Firebase 控制台中,您从函数中获取日志
email verified?你试过没有console.log(func)的前端吗? -
完全正确,没有日志的结果相同
-
你在前端初始化了你的firebase项目?而且你的函数也在
us-central1中运行? -
是的,这一切都完成了,这是我拥有的唯一具有内在承诺的功能,其他功能完美
标签: node.js firebase firebase-realtime-database promise google-cloud-functions