Skip to content

Conversation

HYACCCINT
Copy link

No description provided.

@HYACCCINT HYACCCINT requested a review from jhuleatt April 26, 2024 20:25
Comment on lines 26 to 27
exports.callGemini = onCall({secrets: [geminiToken]}, async (request) => {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before calling Gemini, let's look for both appcheck and auth, but gate each with its own boolean parameter (https://firebase.google.com/docs/functions/config-env?gen=2nd#parameter_types) so devs can choose whether they want auth/app check or not.

Something like:

// ...imports

const appCheckRequired = defineBoolean("APP_CHECK_REQUIRED");
const authRequired = defineBoolean("AUTH_REQUIRED");

// ...other setup

exports.callGemini = onCall(
  {
    enforceAppCheck: appCheckRequired, // Reject requests with missing or invalid App Check tokens.
  },
  (request) => {
    if (authRequired.val() && !request.auth) {
      throw new HttpsError(
        "failed-precondition",
        "The function must be called while authenticated.",
      );
    }

    // ...call Gemini
  },
);

@@ -15,3 +15,4 @@
packages:
- 'Node/**'
- 'Node-1st-gen/**'
- "!Node-1st-gen/image-maker/**"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove before merging

"@google/generative-ai": "^0.5.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.1",
"node-fetch": "^2.6.7"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is node-fetch needed for this sample?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants