title: Firebase Function error and because of it Device to device Notification got Stuck
body: <p>I just got my hands on Firebase Functions and initially, everything was going correct, but now I am facing with the following Error. I am providing error and my codes below.</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  
  // // Create and Deploy Your First Cloud Functions
  // // https://firebase.google.com/docs/functions/write-firebase-functions
  //
  exports.sendNotification = functions.database.ref('/Notification/{user_id}/{notification_id}').onWrite(event =&gt;{
  
    const user_id = event.params.user_id;
    const Notification = event.params.Notification;
  
    console.log('We have a Notification to send to :', user_id);
  
    if (!event.data.val()) {
  
      return console.console.log('A Notify has been deleted from the database :', notification_id);
  
    }
  
    const devicetoken = admin.database().ref(`/Users/{user_id}/device_token`).once('value');
  
    return devicetoken.then(result =&gt;{
  
      const token_id = result.val();
  
  
      const payload = {
        notification: {
          title : "Follower Request",
          body: "You've received a new friend request",
          icon: "default"
        }
      };
  
      return admin.messaging().sendToDevice(token_id, payload).then(response =&gt;{
  
        console.log('This was the notification Feature')
  
      });
  
  
    });
  
  
  });
  </code></pre>
  
  <p>Below is the error which I am receiving in Firebase functions.</p>
  
  <blockquote>
    <p>Error: Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array.
        at FirebaseMessagingError.Error (native)
        at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
        at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
        at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:207:16)
        at Messaging.validateRegistrationTokensType (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:589:19)
        at Messaging.sendToDevice (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:210:14)
        at devicetoken.then.result (/user_code/index.js:36:30)
        at process._tickDomainCallback (internal/process/next_tick.js:135:7)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/RjoMB.png" rel="nofollow noreferrer">Image of firebase function for above error</a></p>
  
  <p><a href="https://i.stack.imgur.com/FTsom.png" rel="nofollow noreferrer">Image for providing an idea of how I have stored device_token_id</a></p>
  
  <p>Any help will be much appreciated.</p>