Can`t receive credential-already-in-use from linkWithCredential on Android
Issue
I have code which should authtentificate user if it already exists or link to anonymous
export const authorizeSkippedUser = function* authorizeSkippedUser(
user,
credentials
) {
try {
let result = yield call(
[user, user.linkAndRetrieveDataWithCredential],
credentials
);
let userProfile = yield call(updateAndRetrieveUserProfile, user.uid);
yield put(AuthActions.authSuccess(userProfile, true));
} catch (ex) {
if (
ex.code &&
ex.code === 'auth/credential-already-in-use' &&
isSocialProvider(credentials.providerId)
) {
yield put(AuthActions.authSignOut());
yield call(
[firebaseAuth, firebaseAuth.signInAndRetrieveDataWithCredential],
credentials
);
} else if (ex.code && ex.code === 'auth/email-already-in-use') {
ex.message = yield* getProvideMessage(ex.email);
throw ex;
} else {
throw ex;
}
}
};
it work fine before but now i cant receive error auth/credential-already-in-use and I dont know why, I think maybe after somewhere update
Project Files
Android
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:3.2.1'
classpath 'io.fabric.tools:gradle:1.25.4'
classpath 'com.google.firebase:firebase-plugins:1.1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
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 {
url 'https://maven.google.com/'
name 'Google'
}
configurations.all {
resolutionStrategy {
force 'com.facebook.android:facebook-android-sdk:4.22.1'
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
def file = new File("$rootDir/../node_modules/react-native/package.json")
def version = new groovy.json.JsonSlurper().parseText(file.text).version
details.useVersion version
}
}
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
android/app/build.gradle:
dependencies {
compile project(':react-native-config')
implementation project(':react-native-fabric')
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation project(':react-native-gesture-handler')
implementation project(':appcenter-crashes')
implementation project(':appcenter-analytics')
implementation project(':appcenter')
implementation project(':react-native-android-location-services-dialog-box')
implementation project(':react-native-background-timer')
implementation project(':react-native-code-push')
implementation(project(':react-native-device-info')) {
exclude group: "com.google.android.gms" // very important
}
implementation project(':react-native-fbsdk')
implementation project(':react-native-fetch-blob')
implementation(project(':react-native-google-signin')) {
exclude group: "com.google.android.gms" // very important
}
implementation project(':react-native-keep-awake')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-shake-event')
implementation project(':react-native-splash-screen')
implementation project(':react-native-svg')
implementation project(':react-native-vector-icons')
implementation project(':react-native-view-shot')
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleCompatible
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation 'com.android.support:multidex:1.0.1'
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.twitter.sdk.android:twitter:3.0.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation('com.google.firebase:firebase-core:16.0.1') {
force = true
}
implementation('com.google.firebase:firebase-messaging:17.1.0') {
force = true
}
implementation "com.google.firebase:firebase-ads:15.0.1"
implementation "com.google.firebase:firebase-storage:16.0.1"
implementation "com.google.firebase:firebase-perf:16.1.0"
implementation "com.google.firebase:firebase-database:16.0.1"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
implementation("com.google.android.gms:play-services-base:15.0.1") {
force = true
}
implementation("com.google.android.gms:play-services-base:15.0.1") {
force = true
}
implementation('com.google.android.gms:play-services-ads:15.0.1') {
force = true
}
implementation('com.google.android.gms:play-services-auth:15.0.1') {
force = true
}
implementation('com.google.android.gms:play-services-gcm:15.0.1') {
force = true
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
transitive = true
}
}
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
- Operating System:
- [x] MacOS, version:
10.12.6 - [ ] Windows, version:
N/A - [ ] Other, please specify:
N/A
- [x] MacOS, version:
- Build Tools:
Android Studio 3.2
React Nativeversion:0.57.1
React Native Firebaselibrary version:4.3.8
Firebasemodule(s) you're using that has the issue:- [] N/A
- [x] Authentication
- [ ] Analytics
- [ ] Cloud Firestore
- [ ] 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:
- 👉 Donate via Open Collective
- 👉 Follow
React Native FirebaseandInvertaseon Twitter - 👉 Star this repo on GitHub ⭐️
- 👉 Contribute; see our contributing guide
@Salakar
@barbarosh thanks for this, this is still pending a RN change/PR; https://github.com/facebook/react-native/pull/20940
Without this change I can't send extra data with errors across the RN bridge; I'd have to rewrite all the modules to never promise reject and always resolve even on an error and then create the errors and stacks myself in JS and native, for Android & iOS - which is no small task, would be a breaking change internally and would have to be semver major; by far not the best solution - could cause issues.
#1329 #1385 also have the same issues. Feel free to tag in on the RN PR to keep an eye on it.
Sorry this is probably not the answer you're looking for 🙈
@Salakar My problem not related to facebook/react-native#20940
My problem in android module io/invertase/firebase/auth/RNFirebaseAuth.java function link not called onComplete for
user.linkWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
user is present
Urgh sorry - I'm exhausted & misread parts of this, still credential-already-in-use should give additional properties and doesn't - but unrelated yes 🙈
So what you're saying is the linkWithCredential doesn't reject (or resolve) on Android onComplete, or it rejects with the wrong code or no code? So it just hangs?
I see you're on v4.3.8 - if it was working before on this version I'd imagine you've potentially updated the Android SDK version for auth in your build gradle and something there has changed the behavior perhaps (com.google.firebase:firebase-auth:16.0.3) - can you confirm if you changed this (or not) recently on git history and if so which version before?
We have several linkWithCredential tests in place and they are passing on Android & iOS: https://github.com/invertase/react-native-firebase/blob/master/tests/e2e/auth/user.e2e.js#L69 so not sure it's an issue specifically with this library and might be relating to the Firebase Android SDK. I'm guessing you've not had the issue on iOS?
@Salakar yes compileSdkVersion updated from 26 to 27 and build tools for react-native 0.57
@Salakar I reviewed your docs and I decided upgrade rnfirebase, I think problem in react-native 0.57 and rnfirebase 4.3.8
There were issues with an RN 57 change causing things not to clear in dev between RN Reload/Hot reloading/Live Reloading (such as auth state - so things could become non responsive or be in an old auth state), can you try disabling those, fully quitting your app then opening it and testing that auth flow (without triggering a Reload). If it works then it's definitely that issue - v5.1 addresses those issues: https://rnfirebase.io/docs/v5.x.x/release-notes#Authentication (first point in auth)
It not related to reload js, because I have this bug in production build
Hmm ok, thought I'd check. RN 57 isn't really ideal for 4.3.8 - it was only tested being compatible up to RN 55, anything higher was moved onto RNFB v5.x.x onwards; so I'm not really sure what to advise you other than upgrading to v5.1.0 unfortunately 😞

@Salakar after update rnfirebase problem is resolved
@barbarosh ok that's good to hear that upgrading sorted your issue. For clarification for others coming across this issue could you note which versions you upgraded to? Thanks
Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:
- 👉 Back financially via Open Collective
- 👉 Follow
React Native FirebaseandInvertaseon Twitter - 👉 Star this repo on GitHub ⭐️
@Salakar
JS lib
"react-native-firebase": "5.1.0"
ANDROID
com.google.firebase:firebase-core:16.0.4
com.google.firebase:firebase-messaging:17.3.4
com.google.firebase:firebase-storage:16.0.4
com.google.firebase:firebase-database:16.0.4
com.google.firebase:firebase-auth:16.0.5
com.google.android.gms:play-services-base:16.0.1
com.google.android.gms:play-services-auth:16.0.1
iOS (all modules 5.11.0)
pod 'Firebase/Core', '~> 5.11.0'
pod 'Firebase/Auth', '~> 5.11.0'
pod 'Firebase/Database', '~> 5.11.0'
@barbarosh thank you