I'm following along a tutorial where I'm creating google cloud functions to add dummy data to google Firestore. When I test locally using Firebase Serve, I get an error "Could not load the default credentials" after sending a POST request to the localhost endpoint. However, when I test on production using Firebase Deploy, I get no error after sending a POST request to the production endpoint and the database entry is created successfully.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
let db = admin.firestore();
exports.createScream = functions.https.onRequest((req, res) => {
let scream = {
body: req.body.body,
userHandle: req.body.userHandle,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
};
let addScream = db.collection('screams').add(scream)
.then(ref => {
res.json({message: `Successfully created scream at ${ref.id}`})})
.catch(err => {res.status(500).json({error: `${err}`})});
});