This is probably a setup issue, but I can't for the life of me find the problem :(
I have configured my Android project to include Firebase Auth, following the setup instructions for Android. I then placed an anonymous sign in request in one of my components:
...
import firebase from 'react-native-firebase';
class ConfigProjectType extends Component {
static navigationOptions = {
title: null,
header: null
};
componentDidMount() {
this.props.getEstimationSettings();
console.log('>>>>>>>>>>>>>>>>>>>>>Will sign in!');
firebase.auth().signInAnonymously()
.then((user) => {
console.log('Anonymous user successfully logged in', user);
})
.catch((err) => {
console.error('Anonymous user signin error', err);
});
}
...
When I launch my app on Android (it launches with no errors or warnings, whatsoever), I see the log I added >>>>>>>>>>>>>>>>>>>>>Will sign in!, but I never receive neither an error log nor a success log. It just fails silently. I also checked the Firebase auth dashboard, and no users are added.
It works just fine on the IOS build. I can see the console log out the success message and I can confirm the user was added in my Firebase auth dashboard.
On Android build, I have traced out firebase, firebase.auth() and firebase.auth().signInAnonymously and they all return a value which seems to mean everything is loading just fine. It just doesn't work.
I have enabled anonymous login in my firebase console, and like I said it is working just fine on IOS
If it helps, here are the Android settings:
Within MainApplication.java (note some are disabled with comments, if it matters):
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new RNFirebasePackage(),
//new RNFirebaseAdMobPackage(),
new RNFirebaseAnalyticsPackage(),
new RNFirebaseAuthPackage(),
//new RNFirebaseRemoteConfigPackage(),
//new RNFirebaseCrashPackage(),
new RNFirebaseDatabasePackage()
//new RNFirebaseFirestorePackage(),
//new RNFirebaseMessagingPackage(),
//new RNFirebasePerformancePackage(),
//new RNFirebaseStoragePackage()
);
}
android/app/build.gradle File:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Per firebase installation instructions: Google Play services from 11.2.0 onwards require their dependencies to be downloaded from Google's Maven respository so add the required reference to the repositories section of the project level build.gradle
url 'https://maven.google.com'
}
}
}
android/app/build.gradle File:
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.embp.devstimate"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
//Firebase start---
// RNFirebase required dependencies
compile(project(':react-native-firebase')) {
transitive = false
}
compile "com.google.firebase:firebase-core:11.2.0"
// If you are receiving Google Play API availability issues, add the following dependency
//compile "com.google.android.gms:play-services-base:11.2.0"
// RNFirebase optional dependencies
//compile "com.google.firebase:firebase-ads:11.2.0"
compile "com.google.firebase:firebase-auth:11.2.0"
//compile "com.google.firebase:firebase-config:11.2.0"
//compile "com.google.firebase:firebase-crash:11.2.0"
compile "com.google.firebase:firebase-database:11.2.0"
//compile "com.google.firebase:firebase-firestore:11.2.0"
//compile "com.google.firebase:firebase-messaging:11.2.0"
//compile "com.google.firebase:firebase-perf:11.2.0"
//compile "com.google.firebase:firebase-storage:11.2.0"
//Firebase end---
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
I have not tested any other modules on Android, but figured it's enough to know that auth does not work.
Thanks in advance!
Could you check logcat in Android studio and see if Firebase logging is saying anything? Also make sure play services is up to date on the device you're testing on.
I think I'm having the same issue with signInWithCustomToken.
In my code I call firabase.app("MY_APP_NAME").auth().signInWithCustomToken(token)
and I don't get any success or failure input.
These are my logcat logs filtered for RNFirebaseAuth:
10-06 15:29:27.734 7815-8941/? D/RNFirebaseAuth: RNFirebaseAuth:initialized
10-06 15:29:30.911 7815-8945/? D/RNFirebaseAuth: addAuthStateListener
10-06 15:29:30.916 7815-8945/? D/RNFirebaseAuth: addIdTokenListener
10-06 15:29:32.600 7815-8945/? D/RNFirebaseAuth: signInWithCustomToken
I debugged signInWithCustomToken from RNFirebaseAuth.java:
@ReactMethod
public void signInWithCustomToken(String appName, final String token, final Promise promise) {
Log.d(TAG, "signInWithCustomToken");
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
firebaseAuth.signInWithCustomToken(token)
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
Log.d(TAG, "signInWithCustomToken:onComplete:success");
promiseWithUser(authResult.getUser(), promise);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "signInWithCustomToken:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
}
});
}
and I noticed that even though I reach firebaseAuth.signInWithCustomToken(token) neither
onSuccess nor onFailure are called
I suspect that your play services are out of date... Look through the adb logcat output for errors to that affect.
Logcat doesn't tell me much, however I tried it on a real Android device ( I was on an emulator before) and it works on the Android device. Leads me to a dumb question, does auth/Firebase work on an emulator? I guess I assumed it did since it works on the IOS simulator. Or perhaps I need to configure my emulator in some way to make it work? Maybe play services config as @chrisbianca suggests? Totally new to this so it's hard to connect the pieces and understand how it all comes together. Thanks in advance :)
Yes they do work on the emulator - if you join us on the Discord chat in the main react-native-firebase room, @Salakar talked somebody through how to make sure their play services were up to date earlier today...
I'm trying to use Phone Auth () for react-native, i have sha-1 and Google-services Both intact but still getting the following error
I'm seeing the same thing as @pulkitkkr.
I am running on a physical device, HTC One, Android 5.0.2. Google Play Services (11.5.09) are up to date. All other Firebase services are working properly.
I do have SHA-1 fingerprint's in my Firebase Console for the release.keystore and debug.keystore. Just re-confirmed they match the key exports.
Package name is correct in Firebase Console and in android/app/build.gradle
I've tried clearing out the build folders; android/build and android/app/build. I keep getting the same error below:
[Error: This app is not authorized to use Firebase Authentication. Please verifythat the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed. Is app running on a physical device? ]]
code: 'auth/app-not-authorized',
nativeErrorMessage: 'This app is not authorized to use Firebase Authentication. Please verifythat the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed. Is app running on a physical device? ]
These are my logcat logs filtered for RNFirebaseAuth:
D/RNFirebaseAuth: RNFirebaseAuth:initialized
D/RNFirebaseAuth: addAuthStateListener
D/RNFirebaseAuth: addIdTokenListener
verifyPhoneNumber:+1212******
verifyPhoneNumber:verification:onVerificationFailed
Lets move the null values discussion over to #464.
@brianhiss not sure what I can suggest - this is the Firebase Android SDK returning this issue, are you able to try on another device? Might be the device is failing whatever checks the android SDK does.
Another thing I'd suggest is make sure billing is setup on the console your firebase project and you're on a paid plan - contrary to what others have said on this in the other issue, the firebase website specifically excludes phone auth from the free plan, so you do need to be on a paid plan:

Short of those two suggestions, then I'd perhaps raise an issue on Stackoverflow or with Firebase directly via the support area on console, sorry 馃檲
EDIT: Sorry, have just seen you've said on the other issue that you're on a paid plan.
@embpdaniel v3.0.2 has built in play store version validation checks, be worth upgrading to that and seeing if it flags up any version issues for you. See the release notes: https://github.com/invertase/react-native-firebase/releases/tag/v3.0.1
@Salakar I upgraded to 3.0.2, and well I tested it and it's working, sort of. The first time I ran it, it said it logged in, in logcat, and I saw there as a new user in the firebase console, however I was not sure if the user had been created right then, I think it was, I just wasn't 100% sure because I did not have the console open at that time. So I deleted the user from the console and ran it again. logcat again printed my console log saying I was logged in, and I saw a uid being set to my redux store.
So, the odd thing is that I then went back to the firebase console but there was no user there. It was empty. I closed the app and the emulator, ran everything again to force it to log back in and, again, it did log in, it printed the user's uid, but the firebase console was empty. So I'm not sure how/where it is generating this uid because it is not in the console. Before it tries to authenticate I check with firebase.aut().authenticated and it logs as false. Maybe you can give me some insight on this part.
As far as play store/services availability, no errors/warnings came up. Prior to seeing your comment and upgrading, I had been tinkering around with the android sdk, updating and downloading additional packages, trying to follow the instructions as best as I could, so maybe that did the trick there. It was a bit confusing because some things were not lining up with the instructions and what I saw on Android studio (I use the Android plugin with IntelliJ, and not Android studio directly, so maybe that had something to do with it). Would have liked to understand what exactly fixed it but it's probably safe to assume that a mix of outdated emulator/no google play services package downloaded/outdated packages were probably the reason.
Anyway, let me know if any clue on the auth not saving issue. Thanks for all the help!
@embpdaniel I don't think this is a case of the auth not saving - the token that is stored in the application is valid for around 60 minutes.
1) When you logged in the first time the user was created
2) You deleted the user from the console - note that this does not log the user out automatically
3) When you refreshed the app, the user is still logged in using the pre-existing token even though the user no longer exists
4) Checking the console would show no user
There's a better explanation here: https://stackoverflow.com/questions/35960546/firebase-still-retrieving-authdata-after-deletion/35961217#35961217
Just leaving a note here for anyone else who might come across this issue. I also had the error with . In setting all this up I completely missed the fact that phone auth doesn't work on an emulator. I'd started with iOS where phone auth works fine on the emulator, so I just figured it would work too on Android. Plugged a real device in and was able to authenticate just fine, even on a free plan. So if you're on an emulator, try a real device if you haven't already.
I just ran into this problem. For android, after i switched to a new computer and installed the project by GIT.
For the release you need to your release-key.keystore as explain https://facebook.github.io/react-native/docs/signed-apk-android.html and add the SHA-1 fingerprint to your android app configuration in firebase console.
For the debug you need to run,
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
from ./rootProject/android/ and add the other SHA-1 fingerprint to your android app configuration in firebase console.
I generated sha1 as @trinketmage decsribed, but I'm still facing with the error.. any solution?
Hello, i fix this:
https://developers.google.com/android/guides/client-auth
@TrungDo123456 I fixed it. thank you. do you have any full react native code of phone auth with firebase? I did but it not works always. something throws weird errors, also the when I enter right code, it shows me timeout error.
@adirzoari , [hi guys, you can post message error of you?