Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda