Firebase Firestore not writing any value

Viewed 1366

I am using Firebase Firestore, but it is not storing any value nor giving any error messages.

    private var mCustomerDatabase : FirebaseFirestore =  FirebaseFirestore.getInstance()
    override fun saveUserInfo(uid: String, profile: Database.UserProfile) {
        Log.d(TAG, "saveUserInfo -Inside")

        mCustomerDatabase
            .collection("app")
            .document("users")
            .collection("customers")
            .document(uid)
            .set(profile, SetOptions.merge())
            .addOnSuccessListener { Log.d(TAG, "saveUserInfo - DocumentSnapshot successfully written!") }
            .addOnFailureListener { e -> Log.w(TAG, "saveUserInfo - Error writing document", e) }

    }

Database.UserProfile is a data class like the Google "Custom objects" Example (Obviously with other vars):

data class City(
    val name: String? = null,
    val state: String? = null,
    val country: String? = null,
    val isCapital: Boolean? = null,
    val population: Long? = null,
    val regions: List<String>? = null
)

Rules on Firebase:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write, delete, update: if true;
    }
  }
}

The strange is that there is no error message, it only does not work. The message(saveUserInfo -Inside) is printed, but neither gives the success log not the error log.

It is in a separeted module called model - I dont know if this affect, but it shouldnt.

What could it be? - I tested on onCreate and it writes normally with the same code. So I discart the import or config error.

Update: I have try every sample code from the documentation and not work. Since there is no message at all What I guess that must be is that I am using a modularized app, the gradle app that have the google service is not being found by the implementation of firebase on the module model. The funny thing is that the RealTime database works fine, I think this might be some bug function of FireStone.

I have reported to Google, because even it is some error in my side, it should have some message to say what I did wrong...

I would like to know if there is more people that are having this issue. If you can try to call a Firebase function inside a module called model - You just pass some firebase auth uid to the database and try to create a document with this uid, maybe you can reproduce the error and see if is really a bug

2 Answers

I faced this problem too in react js and my mistake was I used the firebase.auth.signout() method and then fired the firestore query. I removed the auth.signout() and it worked

With me, problem was domain. Go to console / Authentication / Authorized domains and check is your domain in list. If not, write is not working (with no error).

Related