Site name is: 11tybundle.dev
I have written a Netlify function that updates remote data (a Firebase Realtime Database) when a link on the site is clicked. When I run netlify dev locally and click on the links, I can see in realtime that the database is being updated (a count is incremented). I have added all the necessary environment variables to Netlify for access to the Firebase database.
I recently deployed the site to production to test it. I can see the function invocations taking place on the Netlify admin site…in the logs, but the data in the Firebase database is not being updated.
How do you suggest I go about debugging this? I’m at a bit of a loss as to how to instrument the function to provide me with useful info.
Note that this functionality is not critical to the site’s operation, but is just an underlying capability to add some useful data to the site’s visitors.
Thanks in advance for your help and guidance.
@bobmonsour I doubt that you can use the standard Firebase Realtime Database connectivity from a Netlify Function (which is ultimately an AWS Lambda), usually it would be placed directly on the front-end and secured via database security rules.
If you did want to run it via functions you could implement with the REST API.
Thank you, Nathan. Now that I’m reading the database security rules, you definitely have a point.
And while I do see how the REST API could be useful, I am using a function as the operation I’m performing needs to be atomic. I’m essentially doing a read-modify-write with runTransaction as I can’t risk multiple sources reading while others are modifying or writing the same field.
I’ll see if I can make use of the db security rules to allow the simple operation I’m doing via function.
I ended up switching to Firestore and creating a service account to authenticate. I was able to get all this working from a Netlify function. As a result, I didn’t need any client-side JS. The only downside is that I used the ping attribute on the anchor links that I wanted to count and Firefox does not support ping. Fortunately, I’m not seeking absolute accuracy with these counts. Thanks for the nudge.
Thanks for coming back and sharing this with the community!