Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

fix: Token will cause page jump error when reinstalling Halo #240

Merged
merged 3 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}) {
Expand Down
5 changes: 3 additions & 2 deletions src/views/system/Installation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<script>
import adminApi from '@/api/admin'
import migrateApi from '@/api/migrate'
import { mapActions } from 'vuex'

export default {
data() {
Expand Down Expand Up @@ -270,6 +271,7 @@ export default {
this.$set(this.installation, 'url', window.location.protocol + '//' + window.location.host)
},
methods: {
...mapActions(['installCleanToken']),
async handleVerifyIsInstall() {
await adminApi.isInstalled().then((response) => {
if (response.data.data) {
Expand Down Expand Up @@ -305,8 +307,7 @@ export default {
})
},
install() {
adminApi
.install(this.installation)
this.installCleanToken(this.installation)
.then((response) => {
this.$log.debug('Installation response', response)
this.$message.success('安装成功!')
Expand Down