Skip to content

Open source personal finance application

refactor: initApp action

ilkome9bf4539d0b3b
diff --git a/store/app/actions.js b/store/app/actions.js
index 46b2cce1..ce82e11e 100644
--- a/store/app/actions.js
+++ b/store/app/actions.js
@@ -3,42 +3,41 @@ import { onAuthStateChanged } from 'firebase/auth'
import { auth } from '~/services/firebaseHelpers'
export default {
- async initApp ({ rootState, commit, dispatch }) {
+ initApp ({ rootGetters, commit, dispatch }) {
if (this.$router.currentRoute.name === 'login')
commit('setAppStatus', 'loading')
- await dispatch('demo/getDemoDataStatus', null, { root: true })
-
onAuthStateChanged(auth, async (user) => {
if (this.$router.currentRoute.name === 'login')
commit('setAppStatus', 'loading')
- if (user) {
- try {
- if (rootState.user.user && rootState.user.user.uid && rootState.user.user.uid !== user.uid)
- dispatch('clearUserData')
+ if (!user) {
+ dispatch('clearUserData')
+ return
+ }
+
+ try {
+ if (rootGetters['user/userUid'] !== user.uid)
+ dispatch('clearUserData')
- await dispatch('user/initUser', user, { root: true })
- await dispatch('currencies/initCurrencies', null, { root: true })
- await dispatch('categories/initCategories', null, { root: true })
- await dispatch('wallets/initWallets', null, { root: true })
- await dispatch('trns/initTrns', null, { root: true })
- await dispatch('lang/initDbLang', null, { root: true })
- dispatch('trns/uploadOfflineTrns', null, { root: true })
+ await dispatch('demo/getDemoDataStatus', null, { root: true })
+ await dispatch('user/initUser', user, { root: true })
+ await dispatch('currencies/initCurrencies', null, { root: true })
+ await dispatch('categories/initCategories', null, { root: true })
+ await dispatch('wallets/initWallets', null, { root: true })
+ await dispatch('trns/initTrns', null, { root: true })
+ await dispatch('lang/initDbLang', null, { root: true })
+ await dispatch('trns/uploadOfflineTrns', null, { root: true })
- if (this.$router.currentRoute.name === 'login') {
- this.app.context.redirect('/')
- setTimeout(() => {
- commit('setAppStatus', 'ready')
- }, 100)
- }
- }
- catch (e) {
- console.error(e)
+ if (this.$router.currentRoute.name === 'login') {
+ this.app.context.redirect('/')
+ setTimeout(() => {
+ commit('setAppStatus', 'ready')
+ }, 100)
}
}
- else {
- dispatch('clearUserData')
+ catch (e) {
+ console.error(e)
}
})
},