Skip to content

Commit

Permalink
Navigate to login page When auth token failed (#683)
Browse files Browse the repository at this point in the history
fix #682
  • Loading branch information
tzr164 committed Jan 26, 2021
1 parent 24e7f33 commit 8df509b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
Expand Up @@ -47,7 +47,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (null != authority && authority.needLogin()) {
String authorization = request.getHeader("Authorization");
UserController.User user = UserController.tokenMap.get(authorization);
if (null != user && System.currentTimeMillis() - user.getLastUpdateTime() <= 1000 * 60 * 15) {
if (null != user && System.currentTimeMillis() - user.getLastUpdateTime() <= 1000 * 60 * 60) {
user.setLastUpdateTime(System.currentTimeMillis());
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion dubbo-admin-ui/src/components/http-common.js
Expand Up @@ -17,6 +17,8 @@
import axios from 'axios'
import Vue from 'vue'
import HttpStatus from 'http-status'
import router from '@/router'
import i18n from '@/lang'

let instance = axios.create({
baseURL: '/api/dev'
Expand All @@ -38,7 +40,8 @@ instance.interceptors.response.use((response) => {
} else if (error.response.status === HttpStatus.UNAUTHORIZED) {
localStorage.removeItem('token')
localStorage.removeItem('username')
Vue.prototype.$notify.error('Authorized failed,please login.')
Vue.prototype.$notify.error(i18n.t('authFailed'))
router.push({ path: 'login' })
} else if (error.response.status >= HttpStatus.BAD_REQUEST) {
Vue.prototype.$notify.error(error.response.data.message)
}
Expand Down
3 changes: 2 additions & 1 deletion dubbo-admin-ui/src/lang/en.js
Expand Up @@ -195,5 +195,6 @@ export default {
unsupportedHtmlTypeTip: 'Temporarily unsupported form type',
none: 'none'
}
}
},
authFailed:'Authorized failed,please login.'
}
3 changes: 2 additions & 1 deletion dubbo-admin-ui/src/lang/zh.js
Expand Up @@ -195,5 +195,6 @@ export default {
unsupportedHtmlTypeTip: '暂不支持的表单类型',
none: '无'
}
}
},
authFailed:'权限验证失败'
}
16 changes: 8 additions & 8 deletions dubbo-admin-ui/src/main.js
Expand Up @@ -47,14 +47,6 @@ VueClipboard.config.autoSetContainer = true
Vue.use(VueClipboard)
Vue.component('chart', ECharts)

/* eslint-disable no-new */
new Vue({
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')

router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requireLogin)) {
if (localStorage.getItem('token')) {
Expand All @@ -69,3 +61,11 @@ router.beforeEach((to, from, next) => {
next()
}
})

/* eslint-disable no-new */
new Vue({
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')
1 change: 1 addition & 0 deletions dubbo-admin-ui/vue.config.js
Expand Up @@ -39,6 +39,7 @@ module.exports = {
}
},
configureWebpack: {
devtool: process.env.NODE_ENV === 'dev' ? 'source-map' : undefined,
performance: {
hints: false
},
Expand Down

0 comments on commit 8df509b

Please sign in to comment.