You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import * as functions from "firebase-functions"
import { defineSecret } from "firebase-functions/params";
import { HttpsError, onCall } from "firebase-functions/v2/https";
import fetch, { Headers } from 'node-fetch';
const { defineInt, defineString } = require('firebase-functions/params');
const sanityProjectId = defineString('SANITY_PROJECT_ID');
const sanityApiVersion = defineInt('SANITY_API_VERSION');
const sanityToken = defineSecret('SANITY_TOKEN');
// function for modifying feedback type in sanity
export const submitFeedbackToSanity = onCall(
{ cors: ["*"], secrets: [sanityToken] },
async request => {
if (!request.auth) {
// Throwing an HttpsError so that the client gets the error details.
throw new HttpsError(
"failed-precondition",
"The function must be called while authenticated."
)
}
const { feedback, prompt, userId, chatId } = request.data
functions.logger.log("feedback", feedback)
// make http call to sanity api
const sanityUrl = `https://${sanityProjectId.value()}.sanity.studio/v${sanityApiVersion.value()}/data/mutate/production`
const sanityMutation = {
mutations: [
{
create: {
_type: "chatFeedback",
title: (prompt as String).substring(0, 100),
prompt,
userId,
feedback,
chatId,
}
}
]
}
const sanityHeaders = {
"Content-Type": "application/json",
Authorization: `Bearer ${sanityToken.value()}`
}
// return fetch(sanityUrl, {
// method: "POST",
// headers: new Headers(sanityHeaders),
// body: JSON.stringify(sanityMutation)
// })
const test = await fetch(sanityUrl)
return;
})
Steps to reproduce
Simply run the emulators from the CLI and I get an error. Commenting out the use of fetch(sanityUrl) gives me no errors.
Expected behavior
That emulators start with no errors regardless if I am using fetch(sanityUrl)
Actual behavior
I get a very misleading error that I already mentioned here: #6148 (comment)
but to repeat it:
[debug] [2023-07-25T03:59:09.040Z] Got response code 400; body Failed to generate manifest from function source: Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
I don't see how it has anything to do with the above error and it would be great if the runtime was more accurate. I'm assuming it somehow tries to restart my functions and thats when i run into that error? but I only call initializeApp() once ever in my functions
The text was updated successfully, but these errors were encountered:
Environment info
firebase-tools: 12.4.2
2nd gen firebase functions
Platform: macOS
node-fetch: 3.3.1
Test case
import and use node fetch in 2nd gen function.
Steps to reproduce
Simply run the emulators from the CLI and I get an error. Commenting out the use of
fetch(sanityUrl)
gives me no errors.Expected behavior
That emulators start with no errors regardless if I am using
fetch(sanityUrl)
Actual behavior
I get a very misleading error that I already mentioned here: #6148 (comment)
but to repeat it:
I don't see how it has anything to do with the above error and it would be great if the runtime was more accurate. I'm assuming it somehow tries to restart my functions and thats when i run into that error? but I only call
initializeApp()
once ever in my functionsThe text was updated successfully, but these errors were encountered: