I have a generic cloud function:
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
exports.helloWorld = functions.https.onRequest((request, response) => {
cors(request, response, () => {
res.status(200).send("Hello from Firebase!");
});
});
And I am calling it from a client using axios:
axios
.get(
"https://us-central1-dev-imcla.cloudfunctions.net/helloWorld",
)
.then((res) => {
console.log(res);
})
.catch(er=>{
console.log(er);
})
And I have 2 issues:
- I get CORS error.
Access to XMLHttpRequest at 'https://myurl/helloWorld' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. xhr.js?b50d:178 GET https://us-central1-dev-imcla.cloudfunctions.net/helloWorld net::ERR_FAILED
- If i turn on the cors plugin from the browser or if i call the function from postman I get this error:
Error: Forbidden Your client does not have permission to get URL /helloWorld from this server.
Error: Request failed with status code 403 at createError (createError.js?2d83:16) at settle (settle.js?467f:17) at XMLHttpRequest.handleLoad (xhr.js?b50d:61)
And the thing is that I am both authenticated user and I have the cors package in the cloud code.