mesqueeb / vuex-easy-firestore

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
https://mesqueeb.github.io/vuex-easy-firestore
MIT License
234 stars 28 forks source link

Insert dispatch triggers two requests to Firebase ? #301

Closed igor-duspara closed 4 years ago

igor-duspara commented 4 years ago

I have follwing problem with Firestore functions and the insert dispatch. The dispatch is sending two requests. One for inital creating of the Doc and a second one to Update the Doc itself.

That means that my Function are triggered also twice, one for the inital Doc and one for Update. How can i archive that only one request is send without the inital Doc insert?

Config:

import VuexEasyFirestore from "vuex-easy-firestore";
import { Firebase } from "@/services/Fireinit";

export const easyFirestore = VuexEasyFirestore(
  [
    {
      firestorePath: "profiles",
      firestoreRefType: "collection"
      moduleName: "profiles",
      statePropName: "data"
    }
  ],
  { logging: true, FirebaseDependency: Firebase }
);

My call

...
async createNewUser({ dispatch }, user) {
    await dispatch("profiles/insert", {
      id: user.id,
      username: user.username ? user.username : "",
      email: user.email,
    });
  }
...

Firestore function:

const functions = require("firebase-functions");
const admin = require("firebase-admin");

admin.initializeApp();

exports.createdProfile = functions.firestore
  .document("profiles/{userId}")
  .onCreate((snap, context) => {
    console.log("Created:", snap.data());
  });

exports.updatedProfile = functions.firestore
  .document("profiles/{userId}")
  .onUpdate((change, context) => {
    console.log("Update:", change.after.data());
  });
mesqueeb commented 4 years ago

why did you close the issue ?

Sent with GitHawk

mesqueeb commented 4 years ago

@igor-duspara do you still need help?