My project use Firebase App check on iOS using DeviceCheck & App Test, cloud functions have enforcement checking wether auth context.app is undefined or not, simply like:
if (appCheckEnabled == true && appCheckFunctions[functionName] == true) {
if (context.app == undefined) {
appCheckFailure["reason"] = "context is undefined"
appCheckResult["valid"] = false
}
}
Everything work fine on my devices and my team's device and most of users are fine too.
Problem is that i have some users that are rejected on iOS, we try to understand why as we asked us if the app is downloaded via the app store and correct link, we also ask a video of the device and thing is everything looks fine (also check for jailbreak). So i have a few question about app check :
As App check is in beta is it possible to get some false positive result ?
What can be the reason on iOS for the context.app of the cloud function to be undefined ?
Is it possible they get rejected because of the quotas ? I could not find any ways to check if the Apple Device Check quotas have been reached ? Anyone know where i could find stats about it ?
Thank you for any answer that could help understand.
Related
EDIT (ANSWER): There were two issues with my code. One was that I was passing "http://localhost" instead of just "localhost" to the connectFirestoreEmulator line. The second was that I needed to check db._settingsFrozen before running the emulator line in order to prevent it from being double-initialized. I believe this has something to do with how Nuxt runs its code on the server side vs client side: I think Nuxt shares context/state across sessions on the server side, leading to the emulator line getting run more than once.
I have a Nuxt 2 app that I've connected to Firebase production successfully for a while now. I'm trying to set it up now to use the emulator instead of production when in local environment (indicated by an env variable), but I'm getting an error with the Firebase module specifically. There doesn't seem to be any issues using the auth emulator (which I've also set up). Code (plugins/firebase.js):
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
export const services = { auth, db };
export default (context) => {
if (context.env.appEnv === 'dev') {
console.log('dev', parseInt(context.env.firestorePort))
connectFirestoreEmulator(db, 'http://localhost', parseInt(context.env.firestorePort));
connectAuthEmulator(auth, `http://localhost:${context.env.authPort}`);
}
}
I have narrowed it down to the "connectFirestoreEmulator" line which when commented out, there are no errors. When it's included, this is the error I get:
Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.
Finally, when I set the plugin to run on client-side only, it no longer errors out which is odd. I'll probably just keep working with this client-only for now, but I would like to be able to run the firebase stuff on the server too ideally.
Any ideas/guidance is appreciated. Thanks in advance!
I've Googled the relevant terms and found one other question that was similar to my question ("Firebase Error : Firestore has already been started and its settings can no longer be changed." connecting Firebase v9 with Firestore Emulator). However, because I don't have enough reputation on SO, I can't comment to ask the OP if he ever found out what was happening (which I would normally do before asking my own question, but I'm not being given a choice here).
I also even looked at the nuxt-firebase npm package's source code (https://github.com/nuxt-community/firebase-module) to see how they may have set up the emulator, but their plugin/code is written so differently from mine that it was unhelpful.
Unity version 2020.3.22f1,
Firebase SDK 9.0.0 dotnet4
I've imported both the analytics and real-time database SDK.
The Analytics works perfectly fine.
Regarding the database, building an Android app bundle and uploading to internal test or building an APK and uploading directly to my phone or building for IOS and uploading to test-flight all 3 results with an error.
This is how I initialize Firebase-
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
//init analytics
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
DatabaseReference = FirebaseDatabase.DefaultInstance.RootReference;
Debug.Log(JsonConvert.SerializeObject(DatabaseReference.Database.App.Options));
});
This is how I use the database (increment the win field of a specific level) -
DatabaseReference.Child("Levels").Child($"Level{levelNum}").Child("Wins").RunTransaction((mutableData) =>
{
mutableData.Value = Int32.Parse(mutableData.Value.ToString()) + 1;
return TransactionResult.Success(mutableData);
});
Referring to the log above in the DatabaseRefrence initialization, in the editor, I can see all the configuration properties - databaseUrl,apikey,AppId, etc...
Debugging the APK on my phone the Options property only includes the databaseUrl.
And when trying to perform a transaction to the database an error is being thrown -
W/Unity: Exception in transaction delegate, aborting transaction
System.NullReferenceException: Object reference not set to an instance of an object.
at ....(Firebase.Database.MutableData mutableData)
Things I've tried so far-
I've added the SHA1/SHA256 of both my debug Keystore and googles console App integrity
I've checked and the XML files are being generated with all the details successfully at the streamingAssets folder and at Assets\Plugins\Android\FirebaseApp.androidlib\res\values\google-services.xml
I've tried Initializing the Firebase app manually as mentioned here - https://stackoverflow.com/a/66874818/7210967, doing that indeed results with the debug.log above to include all the Options parameters but the same error occurs as if it doesn't actually use it. (I've tried doing that both with the configuration files in place and removed them completely).
I've tried overriding the default app instance Options.
I've read some posts saying that Proguard obfuscation might cause errors with firebase? couldn't find anything related to Unity.
If anyone has any ideas, please share! ty
Transactions in Firebase Realtime Database work a bit differently than you might expect, as they immediately invoke you handler with the client's guess about the current value of the node, which in general is going to be null.
So when you call mutableData.Value in your code, you get back null and you then call ToString() on it, which leads to the error you get. To solve this, first check whether the mutableData.Value is null before invoking methods on it.
int current = mutableData.Value is null ? 0 : Int32.Parse(mutableData.Value.ToString());
mutableData.Value = current + 1;
return TransactionResult.Success(mutableData);
Syntax errors are possible in the above, as it's been a while since I wrote C#.
A transaction send both the SDKs guess and your new value based on that guess to the server, which then does a compare-and-set operation. If the guess doesn't match the actual value in the database, the server rejects the write with the current value, which the client then uses to call your transaction handler again with an updated current guess.
I've configured firebase ab-testing. Everything works fine except there is no impact user on console.
Actually, I can see UI and log show ab-testing is applied.
Moreover, by checking the other StackoverFlow topic, activateFetched also invoked after fetch successfully.
Moreover, I've referenced
Firebase Remote Config A/B testing shows no results after 24 hours
Firebase Remote Config results on initial request
Remote Config A/B Test does not provide results on iOS
But those are no work on my case.
Is there anything miss or any other need to check so that client can response AB testing result to firebase console.
Thanks for your help first.
Code snippet:
[FIRApp configure];
FIRRemoteConfigSettings* configSettings = [[remoteConfig configSettings] initWithDeveloperModeEnabled:YES];
[[FIRRemoteConfig remoteConfig] setConfigSettings:configSettings];
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:duration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
if (status == FIRRemoteConfigFetchStatusSuccess) {
BOOL configFound = [[FIRRemoteConfig remoteConfig] activateFetched];
A couple things to check or take note of:
Make sure you're using and have deployed the latest Remote Config SDK. Earlier versions don't work with A/B test experiments.
Be sure to verify your experiment on a test device by following the documentation here
It can take a couple days for data to come in for your experiment.
Please call the functions in the following order:
fetch()
Call activatefetched() in the completion handler of fetch().
Fire activation event. If you need to call activation event immediately after activatefetched(), add a time delay of a few seconds. This is because activatefetched() process asynchronously and hence the function may not execute completely, before the activation event is fired.
Once done, test a running experiment on test device. In the debug logs search with string "exp_X" where 'X' is the experiment Id. You will find the experiment Id in the URL of the experiment. If you find the experiment ID in the debug logs while executing the code on test device, it means the device was covered in experiment.
Also if the experiment setup is correct, the running experiment will show 1 active experiment user in the console.
About 3 out of 4 times loading the page I get this error from the firestore client SDK (web). This slows development down tremendously. Auth, Realtime DB and Storage work perfectly fine.
Failed to get document because the client is offline.
Is there something I can do about this?
There's currently an interaction between the clients and routing on the backend that results in this problem. As a result the client believes the network is failing and goes offline.
We'll be rolling out a fix for this soon. Exact times I can't promise but this is among our top priority issues to fix.
Thanks for your patience.
I updated all my packages and I ran into this issue.
I enabled offline persistence for my web app and that fixed the problem:
firebase.firestore().enablePersistence()
https://firebase.google.com/docs/firestore/manage-data/enable-offline
For me, the same error happened when
project_id is wrong
port for emulator is 8081 instead of 8080. (when port was 8081 the emulator was working well, with UI opened normally and so on but the error kept showing. I fixed the problem by changing the port back to 8080)
The error message is very misleading.
I have just spent about 3 hours trying to fix it. There was something wrong with my emulator. I had to remove it, then created new and now it is working. So if you face this issue, give it try.
The problem might occur because you're integrating firebase 'web' SDK in your React Native (RN CLI not Expo) app. So in order to use firebase in your react native app you must follow this tutorial: https://rnfirebase.io/
It must work.
For me, just restarting the emulator fixed it.
In my app as well this error occurs at the first run after installation. I was able to get rid of above bug by refreshing/restarting the Activity.
if (e.getMessage().equals("Failed to get document because the client is offline.")){
finish();
startActivity(getIntent());
}
This code must be placed in addOnFailureListener.
In my case, I was using a leading slash in the database URL:
admin.initializeApp({
credential: admin.credential.cert(CREDENTIALS_PATH),
databaseURL: "https://databasename.firebaseio.com/"
// remove this ^
});
I had some problem. but I've just fixed it. check your projectId is correct. when you use cloud firestore, you need it.
export const environment = {
production: false,
firebaseConfig: {
apiKey: 'XYZ',
authDomain: 'XYZ.firebaseapp.com',
databaseURL: 'https://XYZ.firebaseio.com',
storageBucket: 'XYZ.appspot.com',
projectId: 'XYZ' // <--- make sure project ID is here
}
};
For me, enabling ({ synchronizeTabs: true } ) seems to have helped.
Just in case if someone ever faces this issue on the web (server side code), simply try restarting the server and again ping the endpoint that connects to firebase. This worked for me!
In my case I was using Chrome Extension Moesif CORS. I disabled the extension and it worked.
In my case, I was getting this issue along with a warning that I should change my database location as it was in a different region.
I added a databaseURL property in the firebaseconfig with the url of my dsatabase and it worked properly after that.
My problem was that I previously tested my app with the firebase-local-emulator and therefore had some configurations for it still enabled, for example:
Firebase.firestore.apply {
if (DomainConstants.isOnTest) useEmulator("10.0.2.2", 8080)
}
Because I forgot to set isOnTest = false, the app relied on the firebase-local-emulators data (which was not running) and threw client is offline error.
Long story short: Check if you configured your project using firebase-local-emulator and turn it off when you want to use your "real" database
Saw this error in the console, Enabling Datastore might help.
#firebase/firestore: Firestore (9.6.9): Could not reach Cloud
Firestore backend. Connection failed 1 times. Most recent error:
FirebaseError: [code=not-found]: The project my-project does not exist
or it does not contain an active Cloud Datastore or Cloud Firestore
database. Please visit http://console.cloud.google.com to create a
project or
https://console.cloud.google.com/datastore/setup?project=my-project to
add a Cloud Datastore or Cloud Firestore database. Note that Cloud
Datastore or Cloud Firestore always have an associated App Engine app
and this app must not be disabled. This typically indicates that your
device does not have a healthy Internet connection at the moment. The
client will operate in offline mode until it is able to successfully
connect to the backend.
Try to use VPN, It will work!.
Me i switched to VPN and it worked 100%. Sometimes Firebase fail to respond to IPs addresses of some countries.
I know I can manually go to status.firebase.com but I need to be alerted immediately when my firebase app goes down and when it comes back up.
I thought I could possibly use dingitsup.com to send myself a notification, but i don't know where to point it.
I would also like to have the option of automatically displaying a message to my users when Firebase is down to let them know the system is down and its not a problem on their end. Is there a Zapier integration i could use to achieve this?
Any help would be great! Thanks
Programmatically, you could use a service like Pingdom to send yourself a notification, and could ping an endpoint on your-firebase.firebaseio.com/some-public-endpoint.json.
Also, #FirebaseStatus is a good resource actively updated by the Firebase folks.
Could you write something to use the connection state?
https://www.firebase.com/docs/managing-presence.html (broken)
new link: https://firebase.google.com/docs/database/web/offline-capabilities
I use something similar in my apps to detect if the user has a connection, and display a notice if they don't.
I just figured a way
Firebase.enableLogging(function(logMessage) {
if(logMessage && logMessage.indexOf("Long-poll script failed to load") !== -1 && navigator.onLine){
console.error('Its dead Jim! Firebase seems to be down for this user');
}
});
I'm not sure how firebase works under the hoods but I've seen users connected in a previously open tab and if they open a new tab firebase won't connect when it's down.
This logging function is called a lot, and when firebase is down our console.error will be call every ~5s or something.
Make sure to debounce whatever you'll do in the console.error's place.