使用云功能更新文档时如何获取身份验证ID /用户ID
当前我遇到以下错误
TypeError: Cannot read property 'uid' of undefined
at exports.updateUser.functions.firestore.document.onUpdate (/srv/lib/index.js:19:28)
at cloudFunctionNewSignature (/srv/node_modules/firebase-functions/lib/cloud-functions.js:120:23)
at /worker/worker.js:825:24
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
代码:
export const updateUser = functions.firestore.document("user/{userid}/userProfile/{documentid}").onUpdate((change, context) => {
const latestValue : FirebaseFirestore.DocumentData | any = change.after.data()
const usersCount: number = latestValue.followers
if(usersCount == 2)
{
const tempDocu = {
current: true,
lastPost:admin.firestore.FieldValue.serverTimestamp(),
recentPosts:admin.firestore.FieldValue.arrayUnion(null),
users:admin.firestore.FieldValue.arrayUnion(null)
}
const auth = context.params.uid
return admin.firestore().collection("followers/ "+ auth+"/recentPostColl").doc().create(tempDocu)
}
return null
})
文档生成为undefined