You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using firebase auth to sign-in to the application on iOS and Android, emulator and real device.
However, after exiting the app and re-entering once an hour has passed firebase auth is unable to fetch/refresh a new token and authenticate the current user again.
When making a request to firestore, on app startup, to try and fetch the user's data it does not throw an auth error it throws firestore/unavailable, which points to network connection. However, I have tried this on multiple devices and it is consistently not being able to refresh the auth token. I doubt it is network connection because if I just simply sign-in again it re-auths me correctly and fetches my data.
Below is some XCode debug with firebase debug on:
2022-06-25 00:44:52.630794+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000002] Token auto-refresh enabled.
2022-06-25 00:44:52.632236+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000004] Token auto-refresh scheduled in 00:00 for the new token.
2022-06-25 00:44:52.632925+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000017] Does not have valid access token. Estimated expiration date: 2022-06-24 22:08:53 +0000, current date: 2022-06-24 22:44:52 +0000
2022-06-25 00:44:52.634456+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000017] Fetching new token from backend.
2022-06-25 00:44:52.637212+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Firestore][I-FST000001] Using full collection scan to execute query: Query(canonical_id=weatherly-users/b8g3PFda3NV5xBea5q7o0J5DdCk2|f:|ob:__name__asc)
2022-06-25 00:44:52.637697+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Firestore][I-FST000001] Committing transaction: <LevelDbTransaction ExecuteQuery: 0 changes (0 bytes):>
2022-06-25 00:44:52.674947+0200 weatherly[44340:820841] 8.15.0 - [Firebase/Analytics][I-ACS023044] Successful upload. Got network response. Code, size: 204, -1
2022-06-25 00:44:52.689120+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Analytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): -0.9368828535079956
2022-06-25 00:44:52.701770+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Analytics][I-ACS002003] Measurement timer canceled
2022-06-25 00:44:53.231703+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Auth][I-AUT000017] Fetching new token from backend.
2022-06-25 00:44:53.235433+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Firestore][I-FST000001] WatchStream (7fbe0d2480a8) Stream error: 'Unknown: An internal error has occurred, print and inspect the error details for more information.'
2022-06-25 00:44:53.242762+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Firestore][I-FST000001] Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: An internal error has occurred, print and inspect the error details for more information.
2022-06-25 00:44:53.252760+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Firestore][I-FST000001] WatchStream (7fbe0d2480a8) backoff
2022-06-25 00:44:53.255128+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Firestore][I-FST000001] WatchStream (7fbe0d2480a8) start
2022-06-25 00:44:53.869949+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000003] Token auto-refresh re-scheduled in 01:00 because of error on previous refresh attempt.
2022-06-25 00:44:53.870480+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000017] Does not have valid access token. Estimated expiration date: 2022-06-24 22:08:53 +0000, current date: 2022-06-24 22:44:53 +0000
2022-06-25 00:44:53.874458+0200 weatherly[44340:820850] 8.15.0 - [Firebase/Auth][I-AUT000017] Fetching new token from backend.
2022-06-25 00:44:54.004084+0200 weatherly[44340:820840] 8.15.0 - [Firebase/Firestore][I-FST000001] Committing transaction: <LevelDbTransaction Release target: 2 changes (175 bytes):
2022-06-25 00:44:54.792041+0200 weatherly[44340:820842] 8.15.0 - [Firebase/Firestore][I-FST000001] WatchStream (7fbe0d2480a8) Stream error: 'Unknown: An internal error has occurred, print and inspect the error details for more information.'
I have tried getting forcing a refresh of the token after an error is found but that does not seem to work either.
Code to refresh: firebase.auth().currentUser.getIdToken(true);
I am using android/gradle.settingsjetifier=true for Android compatibility?
I am using the NPM package jetifier for react-native compatibility?
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion ="29.0.3"
minSdkVersion =21
compileSdkVersion =30
targetSdkVersion =30
}
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// added for firebase config
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url(newFile(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../android"))
}
maven {
// Android JSC is installed from npm
url(newFile(["node", "--print", "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), "../dist"))
}
google()
mavenCentral()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
android/app/build.gradle:
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'importcom.android.build.OutputFile/** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation. If none specified and * // "index.android.js" exists, it will be used. Otherwise "index.js" is * // default. Can be overridden with ENTRY_FILE environment variable. * entryFile: "index.android.js", * * // https://reactnative.dev/docs/performance#enable-the-ram-format * bundleCommand: "ram-bundle", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ]*/
project.ext.react = [
enableHermes: false,
cliPath: newFile(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() +"/cli.js",
hermesCommand: newFile(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() +"/%OS-BIN%/hermesc",
composeSourceMapsPath: newFile(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() +"/scripts/compose-source-maps.js",
]
apply from: newFile(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../react.gradle")
// for react-native-vector-icons
project.ext.vectoricons = [
iconFontNames: [ 'Feather.ttf', 'FontAwesome.ttf', 'FontAwesome5_Brands.ttf', 'FontAwesome5_Regular.ttf', 'FontAwesome5_Solid.ttf', 'Ionicons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.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/** * The preferred build flavor of JavaScriptCore. * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default.*/def jscFlavor ='org.webkit:android-jsc:+'/** * Whether to enable the Hermes VM. * * This should be set on project.ext.react and mirrored here. If it is not set * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode * and the benefits of using Hermes will therefore be sharply reduced.*/def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId 'com.jadonhansen.weatherly'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 61
versionName "1.8.3"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false// If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
/* Add the firebaseCrashlytics extension (by default, * it's disabled to improve build speeds) and set * nativeSymbolUploadEnabled to true along with a pointer to native libs. */
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
// Caution! In production, you need to generate your own keystore file.// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.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:// https://developer.android.com/studio/build/configure-apk-splits.htmldef versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
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 {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"// From node_modulesdef isGifEnabled = (findProperty('expo.gif.enabled') ?:"") =="true";
def isWebpEnabled = (findProperty('expo.webp.enabled') ?:"") =="true";
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?:"") =="true";
// If your app supports Android versions before Ice Cream Sandwich (API level 14)// All fresco packages should use the same versionif (isGifEnabled || isWebpEnabled) {
implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.0.0'
}
if (isGifEnabled) {
// For animated gif support
implementation 'com.facebook.fresco:animated-gif:2.0.0'
}
if (isWebpEnabled) {
// For webp support
implementation 'com.facebook.fresco:webpsupport:2.0.0'if (isWebpAnimatedEnabled) {
// Animated webp support
implementation 'com.facebook.fresco:animated-webp:2.0.0'
}
}
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
debugImplementation files(newFile(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-debug.aar"))
releaseImplementation files(newFile(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-release.aar"))
} else {
implementation jscFlavor
}
}
// 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 from: newFile(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
System:
OS: macOS 12.3.1
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 89.39 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.15.1 - /usr/local/bin/node
Yarn: Not Found
npm: 8.11.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 29, 30, 31
Build Tools: 29.0.2, 30.0.3
System Images: android-24 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8092744
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 13.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.64.3 => 0.64.3
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Platform that you're experiencing the issue on:
iOS
Android
iOS but have not tested behavior on Android
Android but have not tested behavior on iOS
Both
react-native-firebase version you're using that has this issue:
14.9.4
Firebase module(s) you're using that has the issue:
Important to note that I am using the current authed-in user's ID to fetch their firestore doc.
I am fetching with source: "server" and it fails with firestore/unavailable. Fetching with source: "default" works but for my use case I need to be able to fetch the users doc on app load and I doubt it is a network problem as I am spotting token refresh issues in the console and have tested on multiple devices with fast internet.
If I sign-in again after the app has loaded, and failed to authenticate the first time, it then authenticates properly and fetches user's doc with no problem even with source: "server".
This reminds me of a problem people had where the underlying error was one of a few things
The underlying thing was a failure of the refresh token to exchange correctly for an access token, so after the access token expired the user was locked out
This is not a module error though - it's going to be a duplicate of 4466 or 5522 depending on the underlying cause, so it's not actionable here which means this is close-able
I understand this particular issue is subtle unfortunately, hopefully the pointers above in combination with watching adb logcat and/or Xcode console help
Issue
I am using firebase auth to sign-in to the application on iOS and Android, emulator and real device.
However, after exiting the app and re-entering once an hour has passed firebase auth is unable to fetch/refresh a new token and authenticate the current user again.
When making a request to firestore, on app startup, to try and fetch the user's data it does not throw an auth error it throws
firestore/unavailable
, which points to network connection. However, I have tried this on multiple devices and it is consistently not being able to refresh the auth token. I doubt it is network connection because if I just simply sign-in again it re-auths me correctly and fetches my data.Below is some XCode debug with firebase debug on:
I have tried getting forcing a refresh of the token after an error is found but that does not seem to work either.
Code to refresh:
firebase.auth().currentUser.getIdToken(true);
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:14.9.4
Firebase
module(s) you're using that has the issue:@react-native-firebase/auth
TypeScript
?N
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: