简体   繁体   English

为什么 context.auth 没有出现在 Firebase 函数 onCreate 文档触发器的 context:EventContext 参数中?

[英]Why isn't context.auth appearing in the context:EventContext parameter on the Firebase function onCreate document trigger?

Problem: The optional context.auth.uid is expected to be part of the parameters of a firebase trigger, but is not being provided.问题:可选的 context.auth.uid 应该是 firebase 触发器参数的一部分,但没有提供。

I am writing a document onCreate trigger on Firebase Cloud Functions.我正在 Firebase Cloud Functions 上编写文档 onCreate 触发器。 This trigger will write a sub-collection document using some of the data from the triggering document and the UID of the user who created it.此触发器将使用触发文档中的一些数据和创建它的用户的 UID 编写子集合文档。

A standard trigger function will accept the following标准触发函数将接受以下内容

export const onCreateUnit = functions.firestore.document('/units/{unitId}').onCreate((snap, context) => {

https://firebase.google.com/docs/reference/functions/providers_firestore.documentbuilder.html#oncreate https://firebase.google.com/docs/reference/functions/providers_firestore.documentbuilder.html#oncreate

The context object should include an auth object which would contain the uid and token上下文对象应包含一个身份验证对象,该对象将包含 uid 和令牌

context: {
    ...contextProperties,
    auth: {
        uid: XXXXXX-XXXX-XXXX,
        token: YYYYYYYYYYY
    }
}

Some things to keep in mind.有些事情要记住。

  1. This is an optional property这是一个可选属性
  2. This property should be filled if a user is creating this document如果用户正在创建此文档,则应填写此属性
  3. All documents in the firestore database have a rule implemented protecting against non-users creating documents. firestore 数据库中的所有文档都实施了防止非用户创建文档的规则。
  4. The client side is a React-Typescript project客户端是一个 React-Typescript 项目
  5. The client is signed in to Firebase and waits for the onAuthStateChanged function to pass a user before creating documents.客户端登录到 Firebase 并等待 onAuthStateChanged 函数在创建文档之前传递用户。
  6. No errors are thrown没有错误被抛出
  7. The trigger function is confirmed to be called when the triggering document is created.触发函数在创建触发文档时确认被调用。
  8. The context.auth property is undefined context.auth 属性未定义

Why is there no auth property provided in the context?为什么上下文中没有提供 auth 属性? How can I fix it?我该如何解决?

看起来您没有提供从前端到在一起的数据,请检查您的用户是否已经登录,这发生在我身上几次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase + 反应:在授权 state 中读取文档已更改并将其添加到上下文中 - Firebase + react : read document in auth state changed and add it to context 上下文API:使用处于上下文状态的函数来更改上下文变量。 功能未执行 - Context API: using a function in the context's state to change a context variable. Function isn't executing 为什么我的 React 上下文没有更新? - Why isn't my React context being updated? 一个上下文消费者被渲染了多个孩子,或者一个不是函数的孩子 - A context consumer was rendered with multiple children, or a child that isn't a function 组件内部的 function 不提供 React 上下文 - React context isn't available from function inside component PrivateRoute 在我的 Firebase 身份验证上下文中闪烁 - PrivateRoute Flickering with my Firebase Auth Context React:为什么我的上下文值没有更新? - React: Why isn't my context value updated? React Context + Firebase Auth 未填充 onAuthStateChanged - React Context + Firebase Auth not populating onAuthStateChanged 将数据传递给 Firebase auth.user().onCreate Cloud Function - Pass Data to Firebase auth.user().onCreate Cloud Function 简单计数器不适用于 React 上下文 - Simple counter isn't working with React context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM