firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.62k stars 368 forks source link

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

Open Tom3652 opened 1 year ago

Tom3652 commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[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 commented 1 year ago

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.

stelldogg commented 1 year ago

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 commented 1 year ago

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

davidkessler-ch commented 1 year ago

Same issue here... Works perfectly with 11.0.1

lahirumaramba commented 1 year ago

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?

Tom3652 commented 1 year ago

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

lahirumaramba commented 1 year ago

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

stelldogg commented 1 year ago

@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)
Tom3652 commented 1 year ago

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.

Gregliest commented 1 year ago

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

d66ni commented 1 year ago

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

jeanmartin commented 1 year ago

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

Jzuni97 commented 10 months ago

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

bnuby commented 9 months ago

I downgraded to v10.0.0 and it works well.

davidkessler-ch commented 9 months ago

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

richparker commented 8 months ago

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.

MadalinSava commented 6 months ago

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

Luca-21 commented 3 months ago

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