Seguí este tutorial para configurar una tienda de autenticación de firebase en vuex ( https://www.youtube.com/watch?v=n9cERWIRgMw&list=PL4cUxeGkcC9jveNu1TI0P62Dn9Me1j9tG&index=10 )
Sin embargo, estoy usando Nuxt, lo que hace que el último paso se rompa.
Mi archivo:
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)¿Cómo cometo una mutación desde aquí? Probé muchas cosas, como this.$store, $store, etc.