Search code examples
google-cloud-functionsfirebase-extensions

What is the priority order regarding firebase extension and an onRequest Cloud function?


I have a pre-configured Firebase Stripe extension that will handle the Stripe role responsible for allowing access to premium content. Additionally, I have my own webhook that will call an onRequest function to perform some data migration. The issue is, I want to catch the previous stripeRole before it is changed by the extension. Yet, I want to know if there is any order in which the stripeExtension and the Firebase onRequest cloud function are triggered by a webhook. Both the webhook and the cloud function will be triggered by the same event. is there is a priority for the extension over the on request ?


Solution

  • Firebase Extensions are just prebuilt Cloud Functions here. They take no precedence over other Cloud Functions that run in your project.

    If you want these actions to execute in a certain order, you will have to enforce that order in your application logic - for example:

    • by having your Cloud Function trigger/filter on the result of the Extension, like listening for its updates and inspecting the Firestore data or those - or

    • if the Extensions fires a custom event, to trigger on that.

      A quick scan of the documentation shows that the Run Payments with Stripe extension:

      This extension emits events, which allows you to listen to and run custom logic at different trigger points during the functioning of the extension. For example you can listen to events when a product has been added via the product.created event, or whenever a payment has succeeded through the invoice.payment_succeeded event.

      If those do not allow you to implement your use-case, consider filing a feature request (or better yet: a PR) for adding the required custom event here.