0

in my project I use some cloud functions: one of them sets custom claims, it works properly, I have a second function that when fired should write some data on the realtime Db,but once is fired I get a CORS Error; this is the faulty function:

    exports.insertUser = functions.https.onCall((data)=>{
  const db = admin.database();
  const reference = "userProfile";
  return db.ref(reference).push(data.user).then(()=>{
    return {message: "utente inserito"};
  }).catch((error)=>{
    return error;
  })
});

this is the error that I get:

Access to fetch at 'https://us-central1-trasportostudenti- 
bc19c.cloudfunctions.net/insertUser' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check

firebase's log states that the problem is in my code; any suggestions to fix this error?

arpho
  • 1,518
  • 9
  • 34
  • 54
  • 1
    I don't see that you are enabling CORS, do you have it enabled in your code? Try [enabling CORS](https://stackoverflow.com/questions/42755131/enabling-cors-in-cloud-functions-for-firebase) using this post. – Andres Fiesco Casasola May 13 '22 at 18:05

0 Answers0