相关疑难解决方法(0)

从Firebase的云功能中的Firestore触发器获取用户ID?

在下面的示例中,有没有办法获取写入'offers/{offerId}'的用户的用户ID(uid)?我试着像这里描述的那样做,但它在Firestore中不起作用.

exports.onNewOffer = functions.firestore
  .document('offers/{offerId}')
  .onCreate(event => {
    ...
});
Run Code Online (Sandbox Code Playgroud)

node.js firebase google-cloud-platform google-cloud-functions google-cloud-firestore

11
推荐指数
4
解决办法
6210
查看次数

firebase 云函数 context.auth 字段是否适用于 firestore?

使用firestore时是否可以通过context.auth属性获取触发云功能的用户的uid?

exports.updateReport = functions.firestore
.document('groups/{groupId}/reports/{nursingId}')
.onUpdate((change, context) => {
    const uid : string | undefined = context.auth?.uid;
})
Run Code Online (Sandbox Code Playgroud)

我发现很多关于同一问题的老问题有许多不同的答案。(该功能有效,该功能有时会工作,或者该功能永远不会工作)

在我的本地设置中,我context.auth总是未定义,所以我不知道我是否犯了错误,或者它根本不起作用。如果是这样的话,是否有其他安全的方式来获取触发相应云功能的用户的uid?

firebase google-cloud-platform google-cloud-functions google-cloud-firestore

1
推荐指数
1
解决办法
947
查看次数