diff --git a/src/package-lock.json b/src/package-lock.json --- a/src/package-lock.json +++ b/src/package-lock.json @@ -33,8 +33,7 @@ "vue-i18n": "^8.27.1", "vue-loader": "^15.9.6", "vue-router": "^3.5.3", - "vue-template-compiler": "^2.6.12", - "vuex": "^3.6.2" + "vue-template-compiler": "^2.6.12" } }, "node_modules/@ampproject/remapping": { @@ -11672,15 +11671,6 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, - "node_modules/vuex": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/vuex/-/vuex-3.6.2.tgz", - "integrity": "sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw==", - "dev": true, - "peerDependencies": { - "vue": "^2.0.0" - } - }, "node_modules/watchpack": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.3.1.tgz", @@ -21198,13 +21188,6 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, - "vuex": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/vuex/-/vuex-3.6.2.tgz", - "integrity": "sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw==", - "dev": true, - "requires": {} - }, "watchpack": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.3.1.tgz", diff --git a/src/package.json b/src/package.json --- a/src/package.json +++ b/src/package.json @@ -39,8 +39,6 @@ "vue-i18n": "^8.27.1", "vue-loader": "^15.9.6", "vue-router": "^3.5.3", - "vue-template-compiler": "^2.6.12", - "vuex": "^3.6.2" - }, - "dependencies": {} + "vue-template-compiler": "^2.6.12" + } } diff --git a/src/resources/js/app.js b/src/resources/js/app.js --- a/src/resources/js/app.js +++ b/src/resources/js/app.js @@ -9,12 +9,16 @@ import AppComponent from '../vue/App' import MenuComponent from '../vue/Widgets/Menu' import SupportForm from '../vue/Widgets/SupportForm' -import store from './store' import { Tab } from 'bootstrap' import { loadLangAsync, i18n } from './locale' const loader = '
Loading
' +const routerState = { + afterLogin: null, + isLoggedIn: !!localStorage.getItem('token') +} + let isLoading = 0 // Lock the UI with the 'loading...' element @@ -40,9 +44,9 @@ // Note: You cannot use app inside of the function window.router.beforeEach((to, from, next) => { // check if the route requires authentication and user is not logged in - if (to.meta.requiresAuth && !store.state.isLoggedIn) { + if (to.meta.requiresAuth && !routerState.isLoggedIn) { // remember the original request, to use after login - store.state.afterLogin = to; + routerState.afterLogin = to; // redirect to login page next({ name: 'login' }) @@ -82,10 +86,10 @@ MenuComponent, }, i18n, - store, router: window.router, data() { return { + authInfo: null, isUser: !window.isAdmin && !window.isReseller, appName: window.config['app.name'], appUrl: window.config['app.url'], @@ -99,27 +103,25 @@ $(form).find('.invalid-feedback').remove() }, hasPermission(type) { - const authInfo = store.state.authInfo const key = 'enable' + type.charAt(0).toUpperCase() + type.slice(1) - return !!(authInfo && authInfo.statusInfo[key]) + return !!(this.authInfo && this.authInfo.statusInfo[key]) }, hasRoute(name) { return this.$router.resolve({ name: name }).resolved.matched.length > 0 }, hasSKU(name) { - const authInfo = store.state.authInfo - return authInfo.statusInfo.skus && authInfo.statusInfo.skus.indexOf(name) != -1 + return this.authInfo.statusInfo.skus && this.authInfo.statusInfo.skus.indexOf(name) != -1 }, isController(wallet_id) { - if (wallet_id && store.state.authInfo) { + if (wallet_id && this.authInfo) { let i - for (i = 0; i < store.state.authInfo.wallets.length; i++) { - if (wallet_id == store.state.authInfo.wallets[i].id) { + for (i = 0; i < this.authInfo.wallets.length; i++) { + if (wallet_id == this.authInfo.wallets[i].id) { return true } } - for (i = 0; i < store.state.authInfo.accounts.length; i++) { - if (wallet_id == store.state.authInfo.accounts[i].id) { + for (i = 0; i < this.authInfo.accounts.length; i++) { + if (wallet_id == this.authInfo.accounts[i].id) { return true } } @@ -130,8 +132,8 @@ // Set user state to "logged in" loginUser(response, dashboard, update) { if (!update) { - store.commit('logoutUser') // destroy old state data - store.commit('loginUser') + routerState.isLoggedIn = true + this.authInfo = null } localStorage.setItem('token', response.access_token) @@ -139,14 +141,14 @@ axios.defaults.headers.common.Authorization = 'Bearer ' + response.access_token if (response.email) { - store.state.authInfo = response + this.authInfo = response } if (dashboard !== false) { - this.$router.push(store.state.afterLogin || { name: 'dashboard' }) + this.$router.push(routerState.afterLogin || { name: 'dashboard' }) } - store.state.afterLogin = null + routerState.afterLogin = null // Refresh the token before it expires let timeout = response.expires_in || 0 @@ -168,7 +170,8 @@ }, // Set user state to "not logged in" logoutUser(redirect) { - store.commit('logoutUser') + routerState.isLoggedIn = true + this.authInfo = null localStorage.setItem('token', '') localStorage.setItem('refreshToken', '') delete axios.defaults.headers.common.Authorization @@ -246,7 +249,7 @@ if (status == 401) { // Remember requested route to come back to it after log in if (this.$route.meta.requiresAuth) { - store.state.afterLogin = this.$route + routerState.afterLogin = this.$route this.logoutUser() } else { this.logoutUser(false) @@ -301,7 +304,7 @@ } }, isDegraded() { - return store.state.authInfo && store.state.authInfo.isAccountDegraded + return this.authInfo && this.authInfo.isAccountDegraded }, pageName(path) { let page = this.$route.path @@ -370,10 +373,10 @@ }, // Append some wallet properties to the object userWalletProps(object) { - let wallet = store.state.authInfo.accounts[0] + let wallet = this.authInfo.accounts[0] if (!wallet) { - wallet = store.state.authInfo.wallets[0] + wallet = this.authInfo.wallets[0] } if (wallet) { diff --git a/src/resources/js/bootstrap.js b/src/resources/js/bootstrap.js --- a/src/resources/js/bootstrap.js +++ b/src/resources/js/bootstrap.js @@ -30,7 +30,6 @@ import Btn from '../vue/Widgets/Btn' import BtnRouter from '../vue/Widgets/BtnRouter' import Toast from '../vue/Widgets/Toast' -import store from './store' window.Vue = Vue diff --git a/src/resources/js/store.js b/src/resources/js/store.js deleted file mode 100644 --- a/src/resources/js/store.js +++ /dev/null @@ -1,20 +0,0 @@ -import Vue from 'vue' -import Vuex from 'vuex' - -Vue.use(Vuex) - -export default new Vuex.Store({ - state: { - isLoggedIn: !!localStorage.getItem('token'), - authInfo: null - }, - mutations: { - loginUser (state) { - state.isLoggedIn = true - }, - logoutUser (state) { - state.isLoggedIn = false - state.authInfo = null - }, - } -}) diff --git a/src/resources/vue/App.vue b/src/resources/vue/App.vue --- a/src/resources/vue/App.vue +++ b/src/resources/vue/App.vue @@ -72,7 +72,7 @@ if (this.$root.isDegraded()) { let message = this.$t('user.degraded-warning') - if (this.$store.state.authInfo.isDegraded) { + if (this.$root.authInfo.isDegraded) { message += ' ' + this.$t('user.degraded-hint') } diff --git a/src/resources/vue/Dashboard.vue b/src/resources/vue/Dashboard.vue --- a/src/resources/vue/Dashboard.vue +++ b/src/resources/vue/Dashboard.vue @@ -66,9 +66,8 @@ } }, mounted() { - const authInfo = this.$store.state.authInfo - this.status = authInfo.statusInfo - this.getBalance(authInfo) + this.status = this.$root.authInfo.statusInfo + this.getBalance(this.$root.authInfo) }, methods: { getBalance(authInfo) { @@ -81,7 +80,7 @@ }, statusUpdate(user) { this.status = Object.assign({}, this.status, user) - this.$store.state.authInfo.statusInfo = this.status + this.$root.authInfo.statusInfo = this.status } } } diff --git a/src/resources/vue/Reseller/Dashboard.vue b/src/resources/vue/Reseller/Dashboard.vue --- a/src/resources/vue/Reseller/Dashboard.vue +++ b/src/resources/vue/Reseller/Dashboard.vue @@ -34,9 +34,8 @@ } }, mounted() { - const authInfo = this.$store.state.authInfo - this.status = authInfo.statusInfo - this.getBalance(authInfo) + this.status = this.$root.authInfo.statusInfo + this.getBalance(this.$root.authInfo) }, methods: { getBalance(authInfo) { diff --git a/src/resources/vue/Settings.vue b/src/resources/vue/Settings.vue --- a/src/resources/vue/Settings.vue +++ b/src/resources/vue/Settings.vue @@ -58,7 +58,7 @@ } }, created() { - this.wallet = this.$store.state.authInfo.wallet + this.wallet = this.$root.authInfo.wallet }, mounted() { this.$root.startLoading() diff --git a/src/resources/vue/User/Info.vue b/src/resources/vue/User/Info.vue --- a/src/resources/vue/User/Info.vue +++ b/src/resources/vue/User/Info.vue @@ -158,7 +158,7 @@ }, computed: { isSelf: function () { - return this.user_id == this.$store.state.authInfo.id + return this.user_id == this.$root.authInfo.id }, passwordLink: function () { return this.$root.appUrl + '/password-reset/' + this.passwordLinkCode @@ -283,7 +283,7 @@ axios[method](location, post) .then(response => { if (response.data.statusInfo) { - this.$store.state.authInfo.statusInfo = response.data.statusInfo + this.$root.authInfo.statusInfo = response.data.statusInfo } this.$toast.success(response.data.message) @@ -313,7 +313,7 @@ }) }, showDeleteConfirmation() { - if (this.user_id == this.$store.state.authInfo.id) { + if (this.user_id == this.$root.authInfo.id) { // Deleting self, redirect to /profile/delete page this.$router.push({ name: 'profile-delete' }) } else { diff --git a/src/resources/vue/User/Profile.vue b/src/resources/vue/User/Profile.vue --- a/src/resources/vue/User/Profile.vue +++ b/src/resources/vue/User/Profile.vue @@ -89,9 +89,10 @@ } }, created() { - this.wallet = this.$store.state.authInfo.wallet - this.profile = this.$store.state.authInfo.settings - this.user_id = this.$store.state.authInfo.id + const authInfo = this.$root.authInfo + this.wallet = authInfo.wallet + this.profile = authInfo.settings + this.user_id = authInfo.id }, mounted() { $('#first_name').focus() diff --git a/src/resources/vue/User/ProfileDelete.vue b/src/resources/vue/User/ProfileDelete.vue --- a/src/resources/vue/User/ProfileDelete.vue +++ b/src/resources/vue/User/ProfileDelete.vue @@ -26,7 +26,7 @@ } }, created() { - if (!this.$root.isController(this.$store.state.authInfo.wallet.id)) { + if (!this.$root.isController(this.$root.authInfo.wallet.id)) { this.$root.errorPage(403) } }, @@ -35,7 +35,7 @@ }, methods: { deleteProfile() { - axios.delete('/api/v4/users/' + this.$store.state.authInfo.id) + axios.delete('/api/v4/users/' + this.$root.authInfo.id) .then(response => { if (response.data.status == 'success') { this.$root.logoutUser() diff --git a/src/resources/vue/Wallet.vue b/src/resources/vue/Wallet.vue --- a/src/resources/vue/Wallet.vue +++ b/src/resources/vue/Wallet.vue @@ -215,7 +215,7 @@ mounted() { $('#wallet button').focus() - this.walletId = this.$store.state.authInfo.wallets[0].id + this.walletId = this.$root.authInfo.wallets[0].id this.$root.startLoading() axios.get('/api/v4/wallets/' + this.walletId) diff --git a/src/resources/vue/Widgets/Menu.vue b/src/resources/vue/Widgets/Menu.vue --- a/src/resources/vue/Widgets/Menu.vue +++ b/src/resources/vue/Widgets/Menu.vue @@ -68,7 +68,7 @@ } }, computed: { - loggedIn() { return this.$store.state.isLoggedIn }, + loggedIn() { return !!this.$root.authInfo }, menu() { return this.menuList.filter(item => !item.footer || this.mode == 'footer') }, route() { return this.$route.name } }, diff --git a/src/resources/vue/Widgets/PasswordInput.vue b/src/resources/vue/Widgets/PasswordInput.vue --- a/src/resources/vue/Widgets/PasswordInput.vue +++ b/src/resources/vue/Widgets/PasswordInput.vue @@ -64,8 +64,8 @@ const post = { password, user: this.user } - if (!post.user && this.$store.state.authInfo) { - post.user = this.$store.state.authInfo.id + if (!post.user && this.$root.authInfo) { + post.user = this.$root.authInfo.id } const cancelToken = axios.CancelToken; diff --git a/src/resources/vue/Widgets/Status.vue b/src/resources/vue/Widgets/Status.vue --- a/src/resources/vue/Widgets/Status.vue +++ b/src/resources/vue/Widgets/Status.vue @@ -124,7 +124,7 @@ window.infoRequest = setTimeout(() => { delete window.infoRequest // Stop updates after user logged out - if (!this.$store.state.isLoggedIn) { + if (!this.$root.authInfo) { return; } @@ -179,7 +179,7 @@ let id = this.$route.params[scope] if (scope == 'dashboard') { - id = this.$store.state.authInfo.id + id = this.$root.authInfo.id scope = 'user' } else if (scope =='distlist') { id = this.$route.params.list diff --git a/src/tests/Browser/Pages/Dashboard.php b/src/tests/Browser/Pages/Dashboard.php --- a/src/tests/Browser/Pages/Dashboard.php +++ b/src/tests/Browser/Pages/Dashboard.php @@ -38,7 +38,7 @@ */ public function assertUser($browser, $user) { - $browser->assertVue('$store.state.authInfo.email', $user, '@dashboard-component'); + $browser->assertVue('$root.authInfo.email', $user, '@dashboard-component'); } /**