diff --git a/src/permission.js b/src/permission.js index 3aba12722..69c8b7f88 100644 --- a/src/permission.js +++ b/src/permission.js @@ -5,13 +5,25 @@ import { setDocumentTitle, domTitle } from '@/utils/domUtil' +import adminApi from '@api/admin' const whiteList = ['Login', 'Install', 'NotFound', 'ResetPassword'] // no redirect whitelist -router.beforeEach((to, from, next) => { +router.beforeEach(async(to, from, next) => { to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`)) Vue.$log.debug('Token', store.getters.token) if (store.getters.token) { + if (to.name === 'Install') { + next() + return + } + const response = await adminApi.isInstalled() + if (!response.data.data) { + next({ + name: 'Install' + }) + return + } if (to.name === 'Login') { next({ name: 'Dashboard' diff --git a/src/store/modules/user.js b/src/store/modules/user.js index bdbe300c2..4b2e1c72d 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -26,6 +26,21 @@ const user = { } }, actions: { + installCleanToken({ + commit + }, installData) { + return new Promise((resolve, reject) => { + adminApi + .install(installData) + .then(response => { + commit('CLEAR_TOKEN') + resolve(response) + }) + .catch(error => { + reject(error) + }) + }) + }, refreshUserCache({ commit }) { diff --git a/src/views/system/Installation.vue b/src/views/system/Installation.vue index 1957880ec..7721d0f26 100644 --- a/src/views/system/Installation.vue +++ b/src/views/system/Installation.vue @@ -216,6 +216,7 @@