Search code examples
androidreact-nativepush-notificationfirebase-cloud-messagingtoken

react native android, got FIS_AUTH_ERROR when trying to get firebase messaging device token


I tried to get android device token to send push notification using react native base messaging and react native push notifications library :

I added config in AndroidManifest.xml :

...
   <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <!-- < Only if you are using GCM or localNotificationSchedule() > -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you are using GCM or localNotificationSchedule() > -->
...

And in my App.js

// ----- COMPONENT DID MOUNT ---- //
  async componentDidMount() {
    // ====================================================== //
    // ====================================================== //
    // ====================================================== //
    const granted = messaging().requestPermission();

    if (granted) {
      console.log('User granted messaging permissions!');
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
      firebase
        .messaging()
        .getToken()
        .then((fcmToken) => {
          if (fcmToken) {
            // user has a device token
            console.log('-------- FCM TOKEN -------');
            console.log(fcmToken);
            console.log(JSON.stringify(fcmToken));
            this._setItem(fcmToken);
          } else {
            // user doesn't have a device token yet
            console.log('error');
          }
        });
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
    } else {
      console.log('User declined messaging permissions :(');
    }
    // ====================================================== //
    // ====================================================== //
    // ====================================================== //
  }
  // ----- FIN COMPONENT DID MOUNT ---- //

I got :

Possible Unhandled Promise Rejection (id: 0):

Error: [messaging/unknown] FIS_AUTH_ERROR

NativeFirebaseError: [messaging/unknown] FIS_AUTH_ERROR


Solution

  • In Google Cloud Console, ensure that the API key from google-services.json includes the following permissions:

    • Firebase Cloud Messaging API
    • Firebase Installations API