Push notification works locally but not on uploaded app

Expo SDK version: 3.23.2
Platform: all

Doing push notifications using Firebase cloud functions. They work locally but on the standalone app they messages don’t go out/get received on the device.

Here is the cloud function:

const functions = require(‘firebase-functions’);
var fetch = require(‘node-fetch’)

const admin = require(‘firebase-admin’)
admin.initializeApp(functions.config().firebase);

exports.sendNewBookingNotification = functions.database.ref(’/bookings/{id}’)
.onCreate((snapshot, context) => {

    const original = snapshot.val();
    var user = '';
    var expoToken = '';
    var messages;

return admin.database().ref(‘userProfiles’).orderByChild(“roleId”).equalTo(0).once(‘value’).then(snapshot => {

        snapshot.forEach(function(snap) {
           user = snap.val().userId;  
        }) 
     
        return Promise.resolve(user)

}).then(user => {

return admin.database().ref("devices").orderByChild("userId").equalTo(user).once('value').then(snapshot => {
        snapshot.forEach(function (childSnapshot) {

            expoToken = childSnapshot.val().expoToken;

            messages = {
                "to": expoToken,
                "title": 'xxxxxxxxxxxx',
                "body": 'xxxxxxxxxxxxxxxxxxxxx',
                "sound": "default",
                "badge": 1,
            }
        });
        return Promise.resolve(messages)

    })

}).then(messages => {

        console.log(messages)

        fetch('https://exp.host/--/api/v2/push/send', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                "Accept-encoding": "gzip, deflate",
            },
            body: JSON.stringify(messages)

        });
    })
    .catch(reason => {
        console.log(reason)
    })

});

Sorry Expo version is 38.0.8 not cli version

I’ve also noticed that when notifications that should drop when for actions on the standalone app do not come. But when the app is closed and the app is opened in Expo client later, the pending notification now drop. At a loss So for some reason the notifications go out, but do not drop on the standalone app, but come in when the app is opened in the local client.

Hey @mfonobong,

To clarify, you’re not getting notifications delivered on iOS or Android? Also, the code you shared is hard to follow as it got mangled between code blocks. Can you test notification delivery via our Notif Tool https://expo.io/notifications to see if that works? If so, the issue may reside with your firebase functions code.

Cheers,
Adam

Messages not delivering on android. The same cloud functions work when testing on Expo client. But when the app is uploaded to Play Store. It doesn’t work.

const functions = require('firebase-functions');
var fetch = require('node-fetch')

const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase);

exports.sendNewBookingNotification =  functions.database.ref('/bookings/{id}')
    .onCreate((snapshot, context) => {

        const original = snapshot.val();
        var adminUser = '';
        var expoToken = '';
        var messages;
    
   return admin.database().ref('userProfiles').orderByChild("roleId").equalTo(0).once('value').then(snapshot => {
        
            snapshot.forEach(function(snap) {
                adminUser = snap.val().userId;  
            }) 
         
            return Promise.resolve(adminUser)

    }).then(adminUser => {

    return admin.database().ref("devices").orderByChild("userId").equalTo(adminUser).once('value').then(snapshot => {
            snapshot.forEach(function (childSnapshot) {

                expoToken = childSnapshot.val().expoToken;

                messages = {
                    "to": expoToken,
                    "title": 'xxxxxxxxxxxxxx',
                    "body": 'xxxxxxxxxxxxx',
                    "sound": "default",
                    "badge": 1,
                }
            });
            return Promise.resolve(messages)

        })

    }).then(messages => {

            console.log(messages)

            fetch('https://exp.host/--/api/v2/push/send', {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    "Accept-encoding": "gzip, deflate",
                },
                body: JSON.stringify(messages)

            });
        })
        .catch(reason => {
            console.log(reason)
        })

});