I am testing a cloud function with the firebase emulator. I am having a problem with CORS policy. I tried as well to put:
const cors = require('cors')({ origin: true });
.....
cors(data, context, async () => {...}
This is the full cloud function:
export const createCheckoutSessionGreen = functions.https.onCall(
(data: any, context: any) => {
cors(data, context, async () => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
mode: 'payment',
success_url: window.location.origin,
cancel_url: window.location.origin,
line_items: [
{
price_data: {
currency: 'eur',
product_data: {
name: data,
},
unit_amount: 1.99 * 100,
},
quantity: 1,
},
],
});
return session.id;
});
}
);
But I always get the same error:
Access to fetch at 'http://localhost:5001/..../us-central1/createCheckoutSessionGreen' from origin 'http://localhost:8100' 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.