I am trying to set up cloud functions with firebase and I am having a slightly difficult time getting it set up. I want to set up a function that gets called by an HTTP request. The function would take the information provided, double-check if those values are indeed the same values as the ones found in my firestorm and then execute some Javascript code before responding; this is my code:
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers. const functions = require("firebase-functions"); // The Firebase Admin SDK to access Firestore. const admin = require('firebase-admin'); admin.initializeApp(); // [START trigger] exports.buyCrypto = functions.https.onRequest((request, res) => { // [END trigger] // [START sendError] // Forbidding PUT requests. if (request.method === 'PUT') { return res.status(403).send('Forbidden!'); } // [END sendError] // [START readQueryParam] const uid = request.body.uid const crypto = request.body.crypto const amount = request.body.amount const docRef = admin.firestore().collection("users").doc(uid); docRef.get().then((doc) => { if (doc.exists) { if(crypto === "BTC") { if(doc.data.btc <= amount) { //execute buy return res.status(200).send("Sucess"); } } if(crypto === "ETH") { if(doc.data.btc <= amount) { //execute buy return res.status(200).send("Sucess"); } } } else { // doc.data() will be undefined in this case console.log("No such document!"); } }).catch((error) => { console.log("Error getting document:", error); }); // Push the new message into Firestore using the Firebase Admin SDK. //const writeResult = await admin.firestore().collection('messages').add({original: original}); // Send back a message that we've successfully written the message // [START sendResponse] const formattedResponse = "IDK" return res.status(403).send("Failed"); // [END sendResponse] }); Unfortunatly I cannot seem to find a great deal of documentation for firebase functions and when I try to test it with the emulator through a web browser it goes into infinite loading and does not display an error message so I am finding it impossible to debug anything. Thank you for your time