google-cloud-firestore

Cannot make a generic item in Kotlin

浪尽此生 提交于 2020-07-10 10:26:45
问题 I want to make the following line of code generic: val newItem: Item = documentChange.document.toObject<Item>(Item::class.java) Works fine. However, when I try to make it generic: val addedItem: T = documentChange.document.toObject<T>(T::class.java) Android Studio is complaining: Cannot use 'T' as reified type parameter. Use a class instead. Screenshot How can I make it generic? 回答1: You need to make a function inline and add reified keyword to the generic parameter: inline fun <reified T>

How to use 'I' as reified type parameter in a LiveData<I> class?

旧城冷巷雨未停 提交于 2020-07-10 10:26:38
问题 I'm trying to use generics when subclassing a LiveData<I> class . According to this answer, I have tried this: class ItemLiveData<I>(): LiveData<I>() { override fun onEvent(querySnapshot: QuerySnapshot?, e: FirebaseFirestoreException?) { if (e != null) return for (documentChange in querySnapshot!!.documentChanges) { when (documentChange.type) { DocumentChange.Type.ADDED -> setValue(getItem(documentChange)) //Add to LiveData } } private inline fun <reified I> getItem(doc: DocumentChange) = doc

Can someone access my Firestore database by somehow manipulating client app?

浪子不回头ぞ 提交于 2020-07-10 09:29:32
问题 I am really concerned about the security of my data which I would be storing in Firestore, I want to know If someone somehow can extract google-services.json file from my android app or use some other tools to access my Firestore database. Is it possible If yes how can I prevent it? 回答1: If your app uses Firebase services and makes use of google-services.json, then yes, anyone can extract that data. The issue for app developers isn't how to lock down that data (impossible), the issue is how

Downside of using transactions in google firestore

我们两清 提交于 2020-07-10 09:18:51
问题 I'm developing a Flutter App and I'm using the Firebase services. I'd like to stick only to using transactions as I prefer consistency over simplicity. await Firestore.instance.collection('user').document(id).updateData({'name': 'new name'}); await Firestore.instance.runTransaction((transaction) async { transaction.update(Firestore.instance.collection('user').document(id), {'name': 'new name'}); }); Are there any (major) downsides to transactions? For example, are they more expensive

role based authorization and role based access control flutter

耗尽温柔 提交于 2020-07-10 08:29:13
问题 what im trying to do is to setup a role based authorization (reqular users and subscribed users) and based on roles users gets redirected to different screens. i am STUCK. ive tried different solutions and seen every tutorial there is out there about the concept. i understand how the concept works but having a realy hard time setting it up in my code. im not sure where to declare the subscribed users and how create the function and how to Navigate them! greatful for any help! this is how my

Setting a created timestamp in Firestore with React

余生颓废 提交于 2020-07-10 08:15:49
问题 I'm adding a document to a firestore collection ( inboxItems ) onSubmit of a form. onCreateInboxItem = event => { this.props.firebase.inboxItems().add({ name: this.state.newInboxItemName, created: '', // I need a timestamp field here }) this.setState({ name: '' }); event.preventDefault(); } How do I get the created field to be a timestamp field, with current timestamp as a value? It would need to be consistent across users and timezones. I see firebase.firestore.FieldValue.serverTimestamp()

Setting a created timestamp in Firestore with React

点点圈 提交于 2020-07-10 08:15:18
问题 I'm adding a document to a firestore collection ( inboxItems ) onSubmit of a form. onCreateInboxItem = event => { this.props.firebase.inboxItems().add({ name: this.state.newInboxItemName, created: '', // I need a timestamp field here }) this.setState({ name: '' }); event.preventDefault(); } How do I get the created field to be a timestamp field, with current timestamp as a value? It would need to be consistent across users and timezones. I see firebase.firestore.FieldValue.serverTimestamp()

Working with nested async Firebase calls SwiftUI

五迷三道 提交于 2020-07-10 05:54:10
问题 I am relatively new to async functions and I understand that the firebase getDocument and getDocuments calls are async. I would like both of these calls to finish before I move on to what I was doing in the code. I've been trying to implement this with dispatch groups, but have been unsuccessful thus far. I have code like the following: let myGroup = DispatchGroup() self.errorMessage = "" let usersRef = self.db.collection("Users").document("Users").collection("Users") if self.test == false {

Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined

懵懂的女人 提交于 2020-07-09 20:03:51
问题 I'm creating a e-commerce with Vue & Firebase. Trying to add some cart information from the current logged in user. Strange thing is at the very first time information saved perfectly. When I trying to add some again. That dosent work and show this error. Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined So I have to refresh that page. Then it work again. I cant understand where is the problem. Note: If I try to add any other

get object for all my documents in Cloud Firestore

时光毁灭记忆、已成空白 提交于 2020-07-09 19:56:44
问题 I want to send a JSON of all my docuements in Firestore from my backend created with express The Firestore docs says how to get all documents but the method is with forEach and express can send only once the response. So the problem is that I don't know how to render all forEach in a variable to send once for the headers This is the code of Firestore docs: db.collection('users').get() .then((snapshot) => { snapshot.forEach((doc) => { console.log(doc.id, '=>', doc.data()); }); }) .catch((err)