android – @react-native-firebase/auth: app not authorized Error in signInWithPhoneNumber-ThrowExceptions

Exception or error:

I am trying to set up a react-native project with firebase to signInWithPhoneNumber functionality. I am receiving an error:

NativeFirebaseError: [auth/app-not-authorized] This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed. Is app running on a physical device? ]

My Function call is as follows:

import auth from '@react-native-firebase/auth';

Screen Class
....
getOtp = async () => {

....
auth()
      .signInWithPhoneNumber(`+91${phonenumber}`)
      .then(confirmResult =>
      ....
}

I have tried all the setup instructions for the Firebase connection.

The Steps I have tried are:

  • I have the same package name in the react-native android project and firebase console.
  • Added the SHA1 from signingReport to Firebase Console.
  • Copied the google-services.json to android/app Folder.
  • Linked the Firebase to Android Studio via Google Analytics.

Giving Dummy Mobile Number for Testing works and has no issue but not with actual mobile number.
In android studio debugger, I am getting error issue displaying:

I/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@8b3312c

D/Auth: signInWithPhoneNumber:verification:failed

package details in package.json:

    "@react-native-firebase/app": "^6.3.3",
    "@react-native-firebase/auth": "^6.3.3",
    "@react-native-firebase/firestore": "^6.3.3",
    "@react-native-firebase/functions": "^6.3.3",
    "@react-native-firebase/messaging": "^6.3.3",
    "@react-native-firebase/storage": "^6.3.3",
    "react": "^16.12.0",
    "react-native": "^0.61.5",

config in build.gradle(app):

...
dependencies {
    implementation "com.google.firebase:firebase-auth:19.2.0"
    //implementation "com.google.firebase:firebase-messaging"
    implementation "com.google.firebase:firebase-storage:17.0.0"
    implementation "com.google.firebase:firebase-firestore:17.1.5"
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.android.support:multidex:1.0.3'

    implementation 'org.webkit:android-jsc:+'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.0'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:0.61.5"  // From node_modules
    implementation "com.google.android.gms:play-services-base:17.1.0"
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation "com.google.firebase:firebase-core:17.2.2"

}
...

config in build.gradle(projectname):

...
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        // googlePlayServicesVersion = "16.1.0"
        androidMapsUtilsVersion = "0.5+"
    }
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.5.3')
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
...
How to solve:

I think in order to prevent abuse the firebase phone authentication wont work in emulator. It only works with real device.

But if you want it for testing purpose then you should add use some testing phone number in firebase console that will work in emulator.

Go to your firebase console -> Authentication -> SIGN-IN Method -> Phone and check the “Phone numbers for testing (optional)” field.

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *