Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

335
Vistas
How to get a user's fcm token from Firestore?

I'm struggling getting fcm messages to send and getting the error

Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array.

I am using firebase functions to send the messages. Here is the part of the function that defines the token. In the log, the token is efB_l9RCMEIErl8m...

exports.newUpdateReqText = functions.firestore
  .document('texts/{id}').onCreate(snap => {
    const afterData = snap.data()
    let name = afterData.name;
    let phone = afterData.phone.replace(/[^0-9]+/g, "");
    let created = afterData.created;
    let userId = afterData.userId;

    return admin.firestore()
      .collection('users')
      .doc(userId)
      .get()
      .then(doc => {
        let token = doc.data().fcm_token
        functions.logger.log(token)

        const payload = {
          notification: {
            title: 'Please update your profile',
            message: `Hi ${name}! It looks like your profile isn't complete. Please provide the rest of the required information ASAP. https://mvpeventstaffing.com/profile.`,
          },
          data: {
            "title": 'Please update your profile',
            "body": `Hi ${name}! It looks like your profile isn't complete. Please provide the rest of the required information ASAP. https://mvpeventstaffing.com/profile.`,
            "action_item": "venue",
            "action_id": "1",
            "actionable": "true",
            "priority": "high",
          },
        }

        return admin.messaging().sendToDevice(token, payload)
        .then((response)=> {
        return console.log("Successfully sent message:", response);
        })
        .catch((error) =>{
        console.log("Error sending message:", error);
        });
      })

Reading answers to similar questions on this site, they commonly respond that the way to get the token is this:

 const getdevicetokenpromise = db.ref(`/DriversAvailable/${key}/token`).once('value');

But, from what I can tell, that is with realtime db, not firestore. I get db.ref is not a function when I tried to write it like this.

So is my data being stored the wrong way? Am I accessing it the wrong way? Or is my function to send the message wrong? Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda