运行User onDelete Firebase Cloud Function时出现错误Error in function [undefined:: object is not iterable (cannot read property Symbol(Symbol.iterator))]
(我在函数中键入了错误),这是我的User onCreate函数(类似于超级按钮)的近镜:>
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const FS = admin.firestore();
const FA = admin.auth();
exports.newUser = functions.auth.user().onCreate(async(user)=>{
const fTime = admin.firestore.Timestamp.now()
const day = fTime.toDate().toLocaleDateString().replace('/','-').replace('/','-')
const time = fTime.toDate().toLocaleTimeString('en',{hour12:false})+'.'+fTime.toDate().getMilliseconds()
try {
const act1 = FS.doc(`users/${user.uid}`).create({email:user.email})
const act2 = FS.doc(`globalEvents/${day}`).set({[time]:{time:fTime,source:'Function newUser',description:`Account created for [${user.uid} - ${user.email}]`}},{merge:true})
const promise = await Promise.all(act1,act2)
return promise
}
catch (err) {
return FS.doc(`globalEvents/${day}`).set({[time]:{time:fTime,source:'Function newUser',description:`Error in function [${err.code}:: ${err.message}]`}},{merge:true})
}
})
exports.delUser = functions.auth.user().onDelete(async(user)=>{
const fTime = admin.firestore.Timestamp.now()
const day = fTime.toDate().toLocaleDateString().replace('/','-').replace('/','-')
const time = fTime.toDate().toLocaleTimeString('en',{hour12:false})+'.'+fTime.toDate().getMilliseconds()
try {
const act1 = FS.doc(`users/${user.uid}`).delete()
const act2 = FS.doc(`globalEvents/${day}`).set({[time]:{time:fTime,source:'Function delUser',description:`Account deleted for [${user.uid} - ${user.email}]`}},{merge:true})
const promise = await Promise.all(act1,act2)
return promise
}
catch (err) {
return FS.doc(`globalEvents/${day}`).set({[time]:{time:fTime,source:'Function delUser',description:`Error in function [${err.code}:: ${err.message}]`}},{merge:true})
}
})
对于那些具有Firebase Cloud功能的用户,我拥有“ admin.initializeApp();”在index.js中,上面的内容在exports.newUser = users.newUser" & "exports.delUser = users.delUser
由于我将其布置为异步性质(再次,onCreate可以完美运行),它仍然会删除用户的文档,但会触发捕获并创建以下文档:
12:48:24.981
description
"Error in function [undefined:: object is not iterable (cannot read property Symbol(Symbol.iterator))]"
source
"Function delUser"
time
November 8, 2020 at 7:48:24 AM UTC-5
答案 0 :(得分:1)
这是因为Promise.all()
接受一个参数,该参数必须是iterable
的Promises,例如Array
。
通过传递如下的数组await Promise.all([act1, act2])
,而不是执行await Promise.all(act1,act2)
,将解决问题。