Firebase React Native Functions seemingly not executing - firebase

I have been using one machine to develop and recently had to switch over to another. I have been going crazy all day because I thought the code was broken (worked on one machine) but then I realized, for some reason anything firebase related will not run. Such as the example code, just seemingly will not execute at all.
Just fyi I am using react native. I read that firebase just recently started supporting it, so I figured there might be some problems. I did the npm install and all that..
This block just simply auth the user. I have used it before and know it works. But for some reason just simply will not execute.
console.log("Start")
firebaseObject.auth().signInWithEmailAndPassword(this.state.email, this.state.password).then(function() {
console.log("Sign In, Go to login")
}.bind(this), function(error) {
// An error happened.
var errorCode = error.code;
var errorMessage = error.message;
console.log("ERROR WITH SIGNIN")
console.log( errorMessage )
});
console.log("end")
if I run this, it will print "Start" and "end" but not run that signInWithEmailandPassword

I've been struggling with the same problem for a week...
I have tried running Firebase in redux-thunks as well as in Redux Sagas, besides trying it directly in a component.
Have you had any luck? It seems Firebase itself is working in on itself (I can make refs), but all async calls just hang there forever, no resolve, no errors either.

Related

Firestore has already been started and cannot be changed - Nuxt 2, Firebase Emulator

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.

Firebase Auth JS signInWithCustomToken hangs

I'm using Ionic+Capacitor to build an app, and in the iOS WebView, this line hangs:
const userCredential = await signInWithCustomToken(auth, token.data.result);
I see on my Firebase console that the user is created when I make the call, so I know it has the intended effect, and I've wrapped it in a try/catch in case it's throwing, but the error bloc never gets called & the function hangs indefinitely. Has anyone else run into issues with this function hanging? Is there a known workaround? Thanks!

FIREBASE WARNING: Invalid query string segment - Warning when deploying simple Firebase Cloud function

This morning I started noticing a large amount of "FIREBASE WARNING: Invalid query string segment" errors in my functions log. In an attempt to figure out what was going on I ended up making various changes to function and deploying all my cloud functions several times.
While doing this I noticed that I was getting the error on a function that:
Does not have a Firebase Query in it.
Has not been invoked in months (it's a test function).
This leads me to believe that a change was made Firebase Cloud Functions recently that may be sporadically generating this error on deploy and/or execution of cloud functions regardless of whether the function has anything to do with real time database queries. Has anybody else noticed this error or have any insight into why it is occurring?
Relevant part of my cloud index.js file is as follows (should be enough to replicate the issue):
const cors = require('cors')({origin: true});
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebaseRef = admin.database().ref();
const firestoreRef = admin.firestore();
exports.testCloudFunctions = functions.https.onRequest((request, response) => {
cors(request, response, () => {
const params = request.query;
console.log(params)
response.status(200).send({success: true, message: "Test Successful", params: params});
});
});
After talking with Firebase support, I learned this bug was introduced in the npm dependency #firebase/database: 0.1.10. You will have this dependency if you also have the latest firebase-admin dependency.
The warning
shouldn't have any impact on the function's overall processing.
If you want to remove the warning, you can force the npm dependency of #firebase/database: 0.1.9. I tested this adjustment and the warning was removed from my Firebase Console Logs.
The support agent also stated the fix has been made, but not released, so I would expect #firebase/database: 0.1.11+ to not experience this bug.
Looks like a recently introduced bug which will hopefully be fixed soon.
We having the same problem today. Maybe some maintenance in the platform. Maybe some Google dev will soon say something about this.
It seems they are having issues with notification.
You can check for the status here: https://status.firebase.google.com/
I am new to Firebase today.
The code snippet I generated for the Firebase db connection had this firebase.js :
<script src="https://www.gstatic.com/firebasejs/4.10.0/firebase.js"></script>
This is generating the message : 'FIREBASE WARNING: Invalid query string segment:', but is also returning the data.
If I use a different version of firebase.js, either .../4.8.0/... or .../4.9.0/... , no error/warning message is generated.
I am running Google Chrome on Windows 10.
Update: It's officially a bug and you can ignore it until they release a fix in the next update or add version of #firebase/database: 0.1.9 to dependencies if you don't want to wait.
Seems like an internal error or change. Also getting this firebase warning and my code was working fine yesterday using '' syntax as well. However my function still works. Looks like they're doing some heavy dev work on it as its in beta and issues are coming up now and then.
Wait for fix or report here:
https://firebase.google.com/support/contact/bugs-features/
Status here (fixes usually take time to appear on here):
https://status.firebase.google.com/
Copy of 48830081 and possibly 48832566

Stream removed error in Firebase Functions

I have a function that runs on the creation of a new user. The function typically fails on the first call after not being called for a while. I'm hoping someone could help me figure out what could be causing this.
export const onUserCreate = functions.auth.user().onCreate(event => {
const user: User = {
userId: event.data.uid,
email: event.data.email
};
return db.doc(`users/${user.userId}`).set(data);
});
As I use the same like below and it works well:
exports.onUserCreate = functions.auth.user().onCreate(event => {
const user = event.data
console.log(user);
})
This is hardly a permanent answer as this is something Google seems to be looking into.
In the meantime though I did some research on similar error messages across the Google libraries and it looks like it happens occasionally when you initialise a Google library outside of a function (ie. at the top of your file).
I've added this line within the function being executed instead of within the global scope and it looks to have stopped the error:
const datastore = require('#google-cloud/datastore')({});
For example instead of:
const datastore = require('#google-cloud/datastore')({});
module.exports.myFunction = function() {
datastore.get(key).then()....
}
you do
module.exports.myFunction = function() {
const datastore = require('#google-cloud/datastore')({});
datastore.get(key).then()....
}
That would go for Firebase libraries too – not just datastore. This isn't best-practice and should be changed back when the bug is fixed.
This seems to be an error with Firebase Functions right now and is being looked into.
EDIT:
Hello all, Sebastian from the Firestore SDK team here. We believe this
issue is related to the recent update of the GRPC Client SDK and have
been running tests with GRPC 1.7.1. So far, we have not been able to
reproduce this issue with this older GRPC version.
#google-cloud/firestore is now at 0.10.1. If you update your
dependencies, you will be able to pull in this release.
Thanks for your patience.
Sebastian
I had the same issue. Turns out this is a bug in the Firestore Node module. Update #google-cloud/firestore to version 0.10.1 and it should fix the issue.

Firebase Functions: Unclear "connection error"

I am getting this error every so many runs with my HTTP Firebase Cloud Function:
Function execution took ****ms, finished with status: 'connection error'
It happens inconsistently but I can't quite narrow down what the problem is. I don't believe the error is in my app as it's not showing an error printout. And my own connection with firebase while running this cloud function isn't cutting out.
Any ideas why Firebase randomly fails cloud function executions with "connection error"?
Function execution took ****ms, finished with status: 'connection error' or ECONNRESET usually happens when a function doesn’t know whether a promise resolved or not.
Every promise must be returned, as mentioned in the docs here. There is also a blog post (with helpful video!) about this.
A couple of examples of unreturned promises:
exports.someFunc = functions.database.ref('/some/path').onCreate(event => {
let db = admin.database();
// UNRETURNED PROMISE
db.ref('/some/path').remove();
return db.ref('/some/other/path').set(event.data.val());
});
exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {
return event.data.ref.set('world').then(snap => {
// UNRETURNED PROMISE
admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);
});
});
exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {
// UNRETURNED PROMISE
event.data.ref.set('world').then(snap => {
return admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);
});
});
To help catch this mistake before deploying code, check out this eslint rule.
For an in-depth look at promises, here are some helpful resources:
Mozilla docs
Ponyfoo promises deep dive
Links to the ECMA standard
Egghead.io course
Even though this question has an approved answer, you may have followed the steps in that answer and still reached a point where the error was still occurring.
In that case, we were informed by GCP that there's a known issue with Node 8 CFs and this connection error, for which the workaround is to update the node version to 10.
Related github issue: https://github.com/firebase/firebase-functions/issues/429
Specific comment: https://github.com/firebase/firebase-functions/issues/429#issuecomment-577324193
I think it might be too many simultaneous firebase database connections :/ https://groups.google.com/forum/#!topic/firebase-talk/4RjyYIDqMVQ
I faced the same issue while deploying uninstallTracking event to firebase for android device,
Turns out that the property I was trying to access was available for only some users ,
So when it couldn't find the property for those other users it gives this error
So first just check the property you are trying to access is there or not
I've been getting this on an HTTP trigger that immediately calls response.end() with no other code!
I had a very complex function that was working great then it stopped working due to this error. I tried for hours playing with my code until there was nothing left but a response.end() and still the error persisted.
I found that by deleting the trigger (deploying my triggers with the offending trigger commented out), then deploying again with the trigger uncommented seems to have fixed it.
Perhaps there is a bug that works in that gets reset when you delete the trigger in the cloud.
Hope this saves somebody some frustration.
it could be outdated libraries.
go to terminal
inside functions folder write command
npm outdated
this will show all libraries to require to be updated.
To update libraries write command
npm update
deploy cloud functions with
firebase deploy --only functions
For debugging purposes, I did the following:
response.send(someArray.length)
...which resulted in the following:
response.send(218)
...which resulted in a bodyless response, just a "status code" (namely 218) being sent. To fix this, I did:
response.send("count: " + someArray.length)

Resources