I have been trying to invoke a Firebase Cloud Function without success.
The sucessfully deployed function is:
functions.logger.info("Hello logs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // this logs
exports.createAuthToken = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", { structuredData: true }); // this doesn't log
response.send("Hello from Firebase!");
});
The first line of the code shows up in the logs, but the third line doesn't when called from an external web client. When I test / run the function from the Google Cloud console, both logs show up.
In the web client, I get the error message:
Access to fetch at 'https://us-central1-my-project.cloudfunctions.net/create-auth-aoken?ot-auth-code=xyz' from origin 'https://my-client-url' has been blocked by CORS policy: 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.
So I resolve the cors issue as the documentation suggests like this:
const cors = require('cors')({
origin: true,
});
functions.logger.info("Hello logs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // this logs
exports.createAuthToken = functions.https.onRequest((request, response) => {
cors(request, response, () => {
functions.logger.info("Hello logs >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!", { structuredData: true }); // this still doesn't
response.send("Hello from Firebase!");
});
});
I am calling the function like this:
https://us-central1-my-project.cloudfunctions.net/create-auth-token?ot-auth-code=${code}&id-token=${token}
I have tried resolving the cors problem in every way I can possibly find, but it will not work.
How should I configure this exactly to make it work?