Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
Why im getting this error invalid Payload?
import admin from "firebase-admin";

async function notifyUser(message ,title, photoURL,token , uid , notificationsOn ) {

  const messages = [];

  const payload = {
    notification: {
      title: title,
      body: message,
    },
    data: {
      uid,
    },
    android: {
      notification: {
        image: photoURL,
      },
    },
    apns: {
      payload: {
        aps: {
          "mutable-content": 1,
        },
      },
      fcm_options: {
        image: photoURL,
      },
    },
  };

  try {
 if (token) {
     

   
  messages.push({ token: token, ...payload });
  console.log("yes");
}
    

    if (messages.length && notificationsOn==true) {
      await admin.messaging().sendAll(messages);
      console.log("Token for user, send notification.");
    }
  } catch (error) {
    const functions = require("firebase-functions");

    functions.logger.log("Hello from info. Here's an object:", error);
   

    console.log(photoURL);
  console.log(notificationsOn);
      console.log(token);
      console.log(message);
      console.log(uid);
      console.log(title)
    console.log("No token for user, can not send notification.");
   
    return {error:error.code};
  }

  return;
};

export {notifyUser} ;

The error I get

enter image description here

The line 169 is this line

 await admin.messaging().sendAll(messages);

It's always logging "No token for user cannot send notification". And I don't have any idea why. I checked like 30 times. The logs are not empty and give the correct output. The token is not empty.

It's not working on both android and iOS. But when sending notification via firebase to android or iOS it works. And notification retrieved .

Hope really anyone has and idea. I also tried to send notification from firebase via token. This also works . And as I said I checked every output it should work but does not.

If you think I did something wrong in configuration in my project please tell me what I you think it can be .

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

comes out that adding this statement

token:token like this

  const payload = {
    notification: {
      title: title,
      body: message,
    },
    token: token,
    data: {
      uid,
    },
    android: {
      notification: {
        image: photoURL,
      },
    },
    apns: {
      payload: {
        aps: {
          "mutable-content": 1,
        },
      },
      fcm_options: {
        image: photoURL,
      },
    },
  };

into payload but outside of all other statements fixed the issue.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda