Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS issue with "onFlow" #896

Open
neo-xy opened this issue Sep 10, 2024 · 2 comments
Open

CORS issue with "onFlow" #896

neo-xy opened this issue Sep 10, 2024 · 2 comments

Comments

@neo-xy
Copy link

neo-xy commented Sep 10, 2024

Related issues

node: v20.9.0

**firebase-functions:**5.0.0

**firebase-tools:**13.16.0

**firebase-admin:**13.16.0

[REQUIRED] Test case

fireabase functions code:

`configureGenkit({
plugins: [
firebase(), // Add projectId here
vertexAI(),
],
logLevel: "debug",
enableTracingAndMetrics: false,
});

export const getMenu3 = onFlow(
{
name: "getMenu3",
inputSchema: z.string(),
outputSchema: z.string(),
authPolicy: firebaseAuth((user) => {
}),

},
async (subject) => {
    const prompt =
        `Suggest an item for the menu of a ${subject} themed restaurant`;
    const llmResponse = await generate({
        model: gemini15Flash,
        prompt: prompt,
        config: {
            temperature: 1,
        },
    });
    return llmResponse.text();
}

);
`

Angular code:
async textAI() { try { let ccc = httpsCallable(this.functions, "getMenu3") let b = await ccc("banana"); console.log(b) } catch (e) { console.log(e); } }

[REQUIRED] Steps to reproduce

  • Create Angular application with above code and deploy do fierbase hosting.
  • Create Firebase function in the same firebase project with above code. and deploy it as well

[REQUIRED] Expected behavior

error free response from getMenu3

[REQUIRED] Actual behavior

Error:
I replaced name of the project with -> aaa-bbb-ccc

Access to fetch at 'https://us-central1-aaa-bbb-ccc.cloudfunctions.net/getMenu3' from origin 'https://aaa-bbb-ccc.web.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
us-central1-aaa-bbb-ccc.cloudfunctions.net/getMenu3:1

   Failed to load resource: net::ERR_FAILED

main-73FIL5CQ.js:32 FirebaseError: internal

Were you able to successfully deploy your functions?

No did not.

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@exaby73 exaby73 transferred this issue from firebase/firebase-functions Sep 12, 2024
@tonybaroneee
Copy link
Collaborator

tonybaroneee commented Sep 26, 2024

Hey @neo-xy, could you try adding this httpsOptions block to your onFlow configuration and re-deploying?

{
    name: "getMenu3",
    inputSchema: z.string(),
    outputSchema: z.string(),
    authPolicy: firebaseAuth((user) => {}),
    httpsOptions: {
        cors: true,
    },
    ...

If that doesn't work, you can also try following the steps at https://cloud.google.com/run/docs/authenticating/public#console-ui to enable public access to the Cloud Run service for your function. Note: With this, you may want to add some additional authorization checks in your authPolicy function above.

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

No branches or pull requests

3 participants