Occasionally in my firebase functions log, I encounter an error message stating: "Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information." This error appears randomly within the code snippet below:
/* eslint-disable promise/no-nesting */
/*jshint esversion: 8 */
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const logging = require('@google-cloud/logging');
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
admin.initializeApp({
// credential: admin.credential.cert(serviceAccount),
// databaseURL: "https://removed.firebaseio.com"
});
const db = admin.firestore();
exports.CreateTime = functions.https.onRequest((req, res) => {
var userURL = req.body.uURL;
var userToken = req.body.utoken;
var reqTask = req.body.task1;
var userUID = req.body.uuid;
console.log(userURL)
var request = require("request");
var headers = {
"Authorization": "Bearer " + userToken,
"Content-Type": "application/json",
"Business": userURL
};
var dataString = { "taskId": reqTask };
var options = {
url: "https://api.plutio.com/v1.5/time-tracks",
method: "POST",
headers: headers,
body: dataString,
json: true
};
function callback(error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body);
console.log(body._id)
let timeid = body._id
db.collection("Users")
.doc(userUID)
.set({ currentTimeTrackID: timeid }, { merge: true })
.catch(e => console.log(e));
}
}
request(options, callback);
res.status(200).send("Complete")
});
//End Time API
Although everything seems to be functioning correctly as expected,
db.collection("Users")
.doc(userUID)
.set({ currentTimeTrackID: timeid }, { merge: true })
.catch(e => console.log(e));
}
it retrieves and stores the current time track ID into the database without any issues.
However, there are instances when this error occurs and it affects the usage of the currentTimeTrackID elsewhere inexplicably.
What is even more perplexing is that sometimes the error occurs intermittently, with the functionality working flawlessly for hours on end. Strangely enough, this issue only surfaced recently after weeks of smooth operation.
Any insights or suggestions?