IjzerenHein / firestorter

Use Google Firestore in React with zero effort, using MobX 🤘
http://firestorter.com
MIT License
378 stars 50 forks source link

Collection.add should not add document to the firestore DB when the schema is violated #16

Closed IjzerenHein closed 6 years ago

IjzerenHein commented 6 years ago

Collection.add doesn't check the schema prior to adding a document to Firestore. This can cause invalid documents to be added to the cloud.

add(data: any): Promise<Document> {
        return new Promise((resolve, reject) => {
            const ref = this.ref;
            if (!ref) throw new Error('No valid collection reference');
<<<<< Should validate schema here
            ref.add(data).then(ref => {
                ref.get().then(snapshot => {
                    try {
                        const doc = new this._documentClass(snapshot.ref, {
                            snapshot: snapshot
                        });
                        resolve(doc);
                    } catch (err) {
                        reject(err);
                    }
                }, reject);
            }, reject);
        });
    }
IjzerenHein commented 6 years ago

Fixed by v0.12.1