Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
How to commit vuex muation form within the same file (in Nuxt)

I followed this tutorial to setup a firebase auth store in vuex (https://www.youtube.com/watch?v=n9cERWIRgMw&list=PL4cUxeGkcC9jveNu1TI0P62Dn9Me1j9tG&index=10)

However, I'm using Nuxt which causes the last step to break.

My file:

import { auth } from "~/plugins/firebase.js";
import {
  createUserWithEmailAndPassword,
  signInWithEmailAndPassword,
  signOut,
  onAuthStateChanged,
} from "firebase/auth";

export const state = () => ({
  user: null,
  authIsReady: false,
});

export const mutations = {
  setUser(state, payload) {
    state.user = payload;
    console.log("user state changed:", state.user);
  },
  setAuthIsReady(state, payload) {
    state.authIsReady = payload;
  },
};

export const actions = {
  async signup(context, { email, password }) {
    console.log("signup action");

    const res = await createUserWithEmailAndPassword(auth, email, password);
    if (res) {
      context.commit("setUser", res.user);
    } else {
      throw new Error("could not complete signup");
    }
  },

  async login(context, { email, password }) {
    console.log("login action");

    const res = await signInWithEmailAndPassword(auth, email, password);
    if (res) {
      context.commit("setUser", res.user);
    } else {
      throw new Error("could not complete login");
    }
  },

  async logout(context) {
    console.log("logout action");

    await signOut(auth);
    context.commit("setUser", null);
  },
};

const unsub = onAuthStateChanged(auth, (user) => {
  store.commit("setAuthIsReady", true);
  store.commit("setUser", user);
  unsub();
});

Error:

Uncaught (in promise) ReferenceError: store is not defined
    at eval (index.js?9101:56:1)
    at eval (index-6de4cbb9.js?3d11:2453:1)

How do I commit a mutation from here? I tried loads of things, like this.$store, $store etc.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda