0

Is there any way to integrate Firebase functions or API inside AMP email so that I can list data from Firebase database and also submit data from amp form to Firebase database.

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
  • Take a look at [this](https://stackoverflow.com/questions/49459364/firebase-authentication-in-amp), it might help you. – afarre Jun 03 '21 at 08:07

1 Answers1

1

Yes this can be done.

1. Submitting data from AMP Email to Firebase.

For submitting data, you need to use AMP Form. All that is required is an endpoint with ssl enabled which can accept post data.

<form method="post"
    action-xhr="https://your-firebase-url.com/post"    target="_top">

In firebase, you can achieve this using functions. You can see some examples here and here.

2. List data from firebase. Listing of data from third-party url can be done in amp using this. Data from firebase can be made available by get api accessible via REST endpoint exposed from function again. As in steps 1.

From documentation:

<amp-state> supports fetching remote data via its srcattribute, which fetches JSON from a CORS endpoint. This fetch is performed once and at page load and is useful for ensuring freshness of data (especially when served from a cache).

You can also bind the src attribute for the element. This means that a user action can trigger a fetch of remote JSON data into the page's bindable state.

AMP just need an enpoint. It however can't load Firebase SDK and use non-rest approach. As AMP doesn't permit use of other js libraries.

esafwan
  • 17,311
  • 33
  • 107
  • 166