本文介绍了显示“意外的令牌管理员";尽管声明了管理员,但仍出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行一些顺序的异步操作.但出现错误:
I'm trying to do some sequential asynchronous operation. But getting error:
尽管我已经声明了该变量.这是我的代码
Although I've declared this variable. Here is my code
const admin = require('firebase-admin')
module.exports = {
notificationCount: async (change, context) => {
countRef.collection("notification").doc(context.params.reqID).get().then((requestDoc) => {
console.log("Request Info " + requestDoc.data().reqUserName)
return requestDoc.data();
}).then((requestDocData) => {
const token = await admin.database().ref("/UserInfo/" + notifiedUserID + "/token").once('value');
console.log("UserInfo "+token);
return null;
}).catch((error) => {
console.log("Loading failed: ", error);
});
}
}
推荐答案
您可能现在已经知道了,但是问题实际上不是admin,而是您正在使用async/await执行函数而未声明它是异步的,因此您只需要在函数定义中放入异步,如下所示:
You have probably figured out by now, but the problem is not actually admin, but rather that you are executing a function with async/await without having stated that it is asynchronous, so you just need to put in async in the function definition like so:
.then(async (requestDocData) => {
const token = await admin.database().ref("/UserInfo/" + notifiedUserID + "/token").once('value');
console.log("UserInfo "+token);
return null;
}
这篇关于显示“意外的令牌管理员";尽管声明了管理员,但仍出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!