Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Secrets in Firebase Function V2 Document Trigger

I have a question about Firebase Functions V2, with regards to how to include Google Secrets Manager into the document trigger function.

I know how to do it with OnRequest, the below works fine.

exports.myWebhook = onRequest({secrets: [MY_WEBHOOK_SECRET, MY_TEST_SECRET_KEY]}, async (req, res) => {
    const safe = STRIPE_TEST_SECRET_KEY.value();
}

However I can't seem to get it to work with onDocumentCreated...

exports.myUpdate = onDocumentCreated("/orders/{documentId}", async (event ) => {
 const myAPIKey = MY_OTHER_API.value()
}

Any time I place {secrets: [MY_OTHER_API]} anywhere in this function, it creates an error. If I exclude it then the API key value is just blank.

Any help would be appreciated. Thanks.

Tried placing {secrets: [MY_OTHER_API_KEY]} into the function to allow it access to the Google Secret value.

like image 380
Jay B Avatar asked May 09 '26 20:05

Jay B


1 Answers

Per the API reference, the first parameter is either a document path or a firestore.DocumentOptions object (which extends GlobalOptions where secrets is defined):

exports.myUpdate = onDocumentCreated(
  {
    document: "/orders/{documentId}",
    secrets: [MY_OTHER_API]
  },
  async (event) => {
    const myAPIKey = MY_OTHER_API.value()
    // other steps
  }
)
like image 174
samthecodingman Avatar answered May 11 '26 10:05

samthecodingman