how to solve cors issue while running cloud functions in flutterflow?

Database & APIs

I have two collections event and notification. I want to create a notification document 24 hours before the event time mentioned in event collection.

Below is the code that I have written

const functions = require('firebase-functions');
const admin = require('firebase-admin');
// To avoid deployment errors, do not call admin.initializeApp() in your code

import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

// const cors = require('cors')({origin: true}); 
exports.scheduleNotification = functions.firestore
    .document('event/{eventId}')
    .onCreate(async (snap, context) => {
        const eventData = snap.data();
        const eventDate = eventData.date.toDate(); // Convert Firestore Timestamp to Date
        const now = new Date();
        now.setHours(now.getHours() + 24); // Add 24 hours to the current time

        // Check if the event date is 24 hours away
        if (eventDate.getTime() === now.getTime()) {
            const notificationData = {
                date: admin.firestore.FieldValue.serverTimestamp(),
                notificationType: 'eventNotification',
                sendToRef: eventData.members,
                readByRef: []
            };
        }
    });

But I am getting cors error in this code

What have you tried so far?

I have tried giving access permission in google cloud console but it didn't work.

Did you check FlutterFlow's Documentation for this topic?
Yes
1 reply