Answer the question
In order to leave comments, you need to log in
How to get data from firebase without reloading the page?
I'm trying to do registration / authorization on vue + vuetify.
Vuex is connected.
There is authorization / registration on firebase (Realtime Database) through the form from the page (data is entered into the database).
There are 3 files in the store folder:
1) index.js
export default new Vuex.Store({
state: {
error: null
},
mutations: {
setError(state, error) {
state.error = error
},
clearError(state) {
state.error = null
},
},
getters: {
error: s => s.error
},
modules: {
auth,
info
}
})
actions: {
async login({dispatch, commit}, {email, password}) {
try {
await firebase.auth().signInWithEmailAndPassword(email, password)
} catch (e) {
commit('setError', e)
throw e
}
},
getUid() {
const user = firebase.auth().currentUser
return user ? user.uid : null
},
}
state: {
info: {}
},
mutations: {
setInfo(state, info) {
state.info = info
},
clearInfo(state) {
state.info = {}
}
},
actions: {
async fetchInfo({dispatch, commit}) {
try {
const uid = await dispatch('getUid')
const info = (await firebase.database().ref(`/users/${uid}/info`).once('value')).val()
commit('setInfo', info)
} catch (e) {
}
}
},
getters: {
info: s => s.info
}
<v-form
ref="form"
@submit.prevent="submitAuth">
...
methods: {
async submitAuth() {
const formData = {
email: this.email,
password: this.password
}
try {
await this.$store.dispatch('login', formData)
this.$router.push('/')
} catch (e) {}
},
},
computed: {
name() {
return this.$store.getters.info.name
}
},
Answer the question
In order to leave comments, you need to log in
And if you
add after the line?
await this.$store.dispatch('login', formData)
await this.$store.dispatch('fetchInfo')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question