Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
How to correctly way to use onSnapshot of firebase firestore in Vuex4?

I try to use firebase firestore in my latest vue3.js webapps. I have used vuex4 as sate management in my apps. My apps also use firebase authentication as login, logout, and make new users.

My apps use snapShot function after login, but an error occurred like below.

Uncaught Error in snapshot listener: FirebaseError: Missing or insufficient permissions.

But I have made the code unsubscribe onSnapshot function after logout event. My code is like below:

store/index.js

const store = createStore({
 state: {
  unsubscribe: null,
 },
 actions: {
  startListner(context) {
   context.state.unsubscribe = onSnapshot(
      //something result get proccess
   )
  },
  stopPostsListner(context) {
      context.state.unsubscribe();
    },
 }
})

I made onSnapshot function as vuex actions methods. And then use these functions at index.vue.

index.vue

<script setup>
import { useStore } from "vuex";
import { onMounted, onUnmounted } from "vue";
const store = useStore();

onMounted(() => {
  store.dispatch("startPostsListner");
});
onUnmounted(() => {
  store.dispatch("stopPostsListner");
});
</script>

I thought onSnapshot function unsubscribe after destroying the component, but errors keep occurring.

How correctly way to use onSnapshot in vuex4?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Posting my comment as an answer for better visibility.

From the security rules by changing:

allow read, write: if

from false; to true; will help to fix the error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!