IB MR
IB MR

Reputation: 385

Cloud Function not executed Flutter

I have this cloud function in my index.ts

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();

const db = admin.firestore();
const fcm = admin.messaging();

console.log("osakosak");
export const sendToDevice = functions.firestore
  .document('orders/{orderId}')
  .onCreate(async snapshot => {
    console.log("osakosak2");
    const order = snapshot.data();

    const querySnapshot = await db
      .collection('users')
      .doc(order.ustaID)
      .collection('tokens')
      .get();

    const tokens = querySnapshot.docs.map(snap => snap.id);

    const payload: admin.messaging.MessagingPayload = {
      notification: {
        title: 'New Order!',
        body: `you sold a ${order.day} for ${order.time}`,
        click_action: 'FLUTTER_NOTIFICATION_CLICK'
      }
    };

    return fcm.sendToDevice(tokens, payload);
  });

However, when the document gets added a notification isn't sent. Nor is anything printed. I have deployed the function.

Upvotes: 0

Views: 150

Answers (1)

Furkan
Furkan

Reputation: 322

You need to check your function error logs in your firebase functions. Go to your function named sendToDevice and click show daily logs. Also be sure that collection and document names are correct. I had the same issue and I solved them by checking logs and correcting the collection/document names in function.

Upvotes: 2

Related Questions