简体   繁体   中英

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.

I am writing a document onCreate trigger on Firebase Cloud Functions. 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.

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

The context object should include an auth object which would contain the uid and token

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.
  4. The client side is a React-Typescript project
  5. The client is signed in to Firebase and waits for the onAuthStateChanged function to pass a user before creating documents.
  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

Why is there no auth property provided in the context? How can I fix it?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM