firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[messaging] TypeError: Value is not an object: undefined

Open Tom3652 opened this issue 2 years ago • 20 comments

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MongoDB Atlas Trigger (Realm App)
  • Firebase SDK version: 11.4.1
  • Firebase Product: messaging
  • JS SDK Version: 3.18.0
  • NPM version: I don't know

[REQUIRED] Step 3: Describe the problem

Executing admin.messaging().sendMulticast(message) returns an error and is not working anymore after upgrading to firebase-admin: 11.4.1 from 11.0.1 and with the release of fastify/busboy 1.2.0 :

uncaught promise rejection: TypeError: Value is not an object: undefined

The difference with my previous issue #1902 is that now messaging().sendMulticat(message) is crashing and no longer deliver the push notification.

Steps to reproduce:

  1. Create a MongoDB Atlas trigger
  2. Add firebase-admin as external dependency and make sure it's 11.4.1
  3. Add the service-account.json as a value
  4. Run the code with the below code

Relevant Code:

exports = async function() {

  const admin = require("firebase-admin");
  const json_creds = context.values.get("service_account_value_name");
  	  
    const title = "Test";
    const body = "This is a test";
   
    const message= {
      android: {
        notification: {
          title: title,
          sound: "default",
          body: body,
        },
      },
      apns: {
        payload: {
          aps: {
            alert: {
              title: title,
              body: body,
            },
            mutableContent: 1,
            contentAvailable: 1
          }
        },
      },
      tokens: ["device_token_1", "device_token_2"]
    };
    	
    admin.initializeApp({
        credential: admin.credential.cert(JSON.parse(json_creds))
      });
  
    admin.messaging().sendMulticast(message);

    console.log("Messages sent !");
  }
}

Tom3652 avatar Jan 08 '23 11:01 Tom3652

I have rolled back to 11.0.1 to see the difference and i am getting the following error :

TypeError: Arguments must be Buffers
	at compare (<eval>:344:13(19))
	at node_modules/@fastify/busboy/deps/streamsearch/sbmh.js:181:65(304)
	at node_modules/@fastify/busboy/deps/streamsearch/sbmh.js:82:24(41)
	at node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:107:23(92)
	at T (<eval>:10:22717(45))
	at <eval>:10:25821(108)
	at <eval>:10:25847(113)
	at d (<eval>:10:14414(11))
	at <eval>:10:4454(115)
	at <eval>:10:13336(285)
	at C (<eval>:10:11803(20))
	at A (<eval>:10:11681(31))

But the push notification is sent successfully, in 11.4.1 it's not sent at all.

Tom3652 avatar Jan 08 '23 11:01 Tom3652

I'm seeing the same issue, where updating from 11.4.0 to 11.4.1 is causing this crash. It appears that this change has pushed 'undefined' as a value into a the JWT verify flow, which might match the error. I will try to get my function dependencies to refresh, as it might be a stale package (jsonwebtoken) causing the failure.

stelldogg avatar Jan 10 '23 13:01 stelldogg

No change in behavior after adding jsonwebtoken 9.0.0 as a dependency directly.

stelldogg avatar Jan 10 '23 13:01 stelldogg

Same issue here... Works perfectly with 11.0.1

davidkessler-ch avatar Jan 12 '23 10:01 davidkessler-ch

Hey folks, thank you for reporting this! Are you able to share the complete error logs with us? If you can reproduce the issue in a simple Node.js project, could you provide us with a minimal repro, please?

lahirumaramba avatar Jan 12 '23 16:01 lahirumaramba

Sorry i don't know node JS that much, i only use a MongoDB Atlas Trigger to see this behavior... :(

Tom3652 avatar Jan 14 '23 17:01 Tom3652

No worries, are you able to share a complete error log so we can track down where it is throwing the error?

lahirumaramba avatar Jan 17 '23 21:01 lahirumaramba

@lahirumaramba the errors posted above are all that are given when the error is generated by the MongoDB function, apologies.

If it helps, here are a couple extra details:

payload: {"notification":{"body":"Your video is ready!","title":"New Video"},"tokens":[<my-device-token>]}

call:

const admin = require('firebase-admin');
admin.messaging().sendMulticast(message)

stelldogg avatar Jan 18 '23 02:01 stelldogg

No worries, are you able to share a complete error log so we can track down where it is throwing the error?

Sorry for the late answer, there is no more logs than this from the Atlas trigger... However, i think it can be related to any changes made between the working version and this one that is not working at all.

Tom3652 avatar Mar 14 '23 19:03 Tom3652

Has there been any progress on this? I'm still running into this issue on version 11.7.0

Gregliest avatar Apr 18 '23 23:04 Gregliest

I have the same issue, are there any news about this topic? Actually using version 11.9.0.

d66ni avatar Jul 22 '23 12:07 d66ni

11.10.1, also using MongoDB Atlas functions, same error :/

jeanmartin avatar Jul 28 '23 00:07 jeanmartin

Did anyone every resolve this? Using version 11.11.0 in MongoDB Atlas functions and still getting same error...

Jzuni97 avatar Nov 15 '23 19:11 Jzuni97

I downgraded to v10.0.0 and it works well.

bnuby avatar Dec 12 '23 12:12 bnuby

I can't believe that this has still not been fixed😟. (now using 12.0.0)

davidkessler-ch avatar Dec 19 '23 19:12 davidkessler-ch

Still no update on this?

I get the same error when using 12.0.0. Had to downgrade to 10.0.0 for it to work.

richparker avatar Jan 23 '24 13:01 richparker

Same issue here, 10.0.0 is working but 12 is not.

MadalinSava avatar Mar 05 '24 08:03 MadalinSava

im using the last version 12.1.1 and i have the same issue, did you know any workaroud?

Luca-21 avatar May 27 '24 14:05 Luca-21