React-native-firebase: Error caught at messaging().getToken()

Created on 22 Jan 2019  路  6Comments  路  Source: invertase/react-native-firebase


Issue




The firebase.messaging().getToken() works in most devices I've tested expect a Huawei Nova 3i. When I run the firebase.messaging().getToken() method inside a try block, an error get caught. The error object reads Error: AUTHENTICATION_FAILED. On inspecting the properties of the Error object I get

{
  framesToPop: 1,
  code: messaging/fcm-token-error
}

Using the following code to inspect the error,

console.log('error', error);
for (const field in error) {
    console.log(field, error[field]);
}

gives this
image

Project Files






iOS

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A

Android

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

  • Platform that you're experiencing the issue on:

    • [ ] iOS

    • [x] Android

    • [ ] iOS but have not tested behavior on Android

    • [ ] Android but have not tested behavior on iOS

    • [ ] Both

  • If known, the version of the platform are you experiencing the issue on:

    • ADD_SOMETHING_HERE e.g. iOS 10 or Android API 28

  • Operating System:

    • [ ] MacOS, version: N/A

    • [x] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • ADD_SOMETHING_HERE e.g. Xcode 10, Android Studio 3.2

  • React Native version:

    • 0.57.8

  • React Native Firebase library version:

    • 5.2.0

  • Firebase module(s) you're using that has the issue:

    • [ ] N/A

    • [ ] Authentication

    • [ ] Analytics

    • [ ] Cloud Firestore

    • [x] Cloud Messaging (FCM)

    • [ ] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] Invites

    • [ ] Instance ID

    • [ ] Notifications

    • [ ] Performance Monitoring

    • [ ] Realtime Database

    • [ ] Remote Config

    • [ ] Storage

  • Are you using TypeScript?

    • [x] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [x] No

    • [ ] Yes, I've _not_ ejected

    • [ ] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: N/A




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Most helpful comment

Open AVD manager window in android studio and click "Wipe Data". It could helps a lot
image

All 6 comments

+1

getting the same error when trying to call firebase.messaging().getToken()

EDIT:
Turns out my emulator didn't have google play services installed and the one I tried before that had an older version. After I created a new emulator with API 28 with google play, it worked again.

Please see https://rnfirebase.io/docs/v5.x.x/troubleshooting/android#Google-Play-Services-related-issues and the sections following it on how to check for valid play services installation.

I am still facing this issue while trying to call firebase.messaging().getToken()

Error: AUTHENTICATION_FAILED
    at createErrorFromErrorData (NativeModules.js:152)
    at NativeModules.js:104
    at MessageQueue.__invokeCallback (MessageQueue.js:442)
    at MessageQueue.js:127
    at MessageQueue.__guard (MessageQueue.js:343)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
    at debuggerWorker.js:80
App.js:335 

According to the react-native-firebase documentation, I executed the following function to know the status of my emulator's play services version

async function checkPlayServicesBasicExample() {
  const utils = firebase.utils();

  const {
    isAvailable,
    hasResolution,
    isUserResolvableError,
  } = utils.playServicesAvailability;

  // all good and valid \o/
  if (isAvailable) return Promise.resolve();

  // if the user can resolve the issue i.e by updating play services
  // then call Google Play's own/default prompting functionality
  if (isUserResolvableError) {
    return utils.promptForPlayServices();
  }

  // call Google Play's own/default resolution functionality
  if (hasResolution) {
    return utils.resolutionForPlayServices();
  }

  // There's no way to resolve play services on this device
  // probably best to show a dialog / force crash the app
  return Promise.reject(
    new Error('Unable to find a valid play services version.')
  );
}

I got a positive result saying that the device has a valid play services installation. I am using an Android emulator with API 29 and Android 10 (Google API)

So far, I don't understand what the issue is

Open AVD manager window in android studio and click "Wipe Data". It could helps a lot
image

I am also facing same issue in nova 7i also install play store and play services

@smismailalam Hi. Have you managed to get notifications to work on your huawei device?

Was this page helpful?
0 / 5 - 0 ratings