Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
CORS Policy error in firebase V9 on an onCall firebase function

I have the problem that as soon as I want to make a call to my firebase functions I get a Cors policy Error. I have already read multiple questions about that but I couldn't find one that solves the issue in the Firebase version 9. The call syntax is different in v9. And I can't figure out how to solve it.

Error:

Access to fetch at 'https://us-central1-mmonitor-19efd.cloudfunctions.net/sendRequest' from origin 'http://localhost:3000' 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.

Firebase Initialization:

import { initializeApp } from 'firebase/app';
import { getFunctions } from 'firebase/functions';

const firebaseConfig = {
  apiKey: "XXXX",
  authDomain: "XXXX",
  projectId: "XXXX",
  storageBucket: "XXXX",
  messagingSenderId: "XXXX",
  appId: "XXXX",
  measurementId: "XXXX"
};
export const firebaseApp = initializeApp(firebaseConfig);
export const functions = getFunctions()

Function Call:

import { firebaseApp, functions } from "./firebase"
import { httpsCallable } from 'firebase/functions';

function sendRequest(e) {
    const sendRequest = httpsCallable(functions, 'sendRequest');
    sendRequest()
}
function App() {
    return (
        <button onClick={sendRequest}>send Request</button>
    );
}
export default App;

Firebase Functions:

const functions = require("firebase-functions");

exports.sendRequest = functions.https.onCall(async(data, context) => {
    console.log("ok")
});

Note: (I am using the emulator at the moment) Note: (I tried to change the location of the server but I am not sure how to do that in the emulator and in the frontend in v9)

Thank you for your time!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I couldn't find a better way than just downgrading to firebase@8.10.0 and using the following code:

Firebase init:

import firebase from "firebase/app";
import "firebase/functions"

const firebaseConfig = {
    apiKey: "XXXX",
    authDomain: "XXXX",
    projectId: "XXXX",
    storageBucket: "XXXX",
    messagingSenderId: "XXXX",
    appId: "XXXX",
    measurementId: "XXXX"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);


firebase.functions().useEmulator("localhost", 5001);


export default firebase

Funcion Call:

import firebase from "./firebase.js";


function sendRequest(e) {
  const sendRequest = firebase.functions().httpsCallable('sendRequest');
  sendRequest()
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this

import { connectFunctionsEmulator } from "firebase/functions";

connectFunctionsEmulator(functions, "localhost", 5001);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda