Skip to content

Commit a426c39

Browse files
perf: Authentication Failure Prompt Optimization
1 parent 4285ec3 commit a426c39

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

frontend/src/assets/svg/401.svg

Lines changed: 29 additions & 0 deletions
Loading

frontend/src/router/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Appearance from '@/views/system/appearance/index.vue'
2121
import Permission from '@/views/system/permission/index.vue'
2222
import User from '@/views/system/user/User.vue'
2323
import Workspace from '@/views/system/workspace/index.vue'
24+
import Page401 from '@/views/error/index.vue'
2425
import { i18n } from '@/i18n'
2526
import { watchRouter } from './watch'
2627

@@ -207,6 +208,13 @@ export const routes = [
207208
name: 'assistantTest',
208209
component: assistantTest,
209210
},
211+
{
212+
path: '/401',
213+
name: '401',
214+
hidden: true,
215+
meta: {},
216+
component: Page401,
217+
},
210218
]
211219
const router = createRouter({
212220
history: createWebHashHistory(),

frontend/src/router/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const appearanceStore = useAppearanceStoreWithOut()
88
const userStore = useUserStore()
99
const { wsCache } = useCache()
1010
const whiteList = ['/login']
11-
const assistantWhiteList = ['/assistant', '/embeddedPage']
11+
const assistantWhiteList = ['/assistant', '/embeddedPage', '/401']
1212
export const watchRouter = (router: any) => {
1313
router.beforeEach(async (to: any, from: any, next: any) => {
1414
await loadXpackStatic()

frontend/src/utils/request.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import axios, {
1111
import { useCache } from '@/utils/useCache'
1212
import { getLocale } from './utils'
1313
import { useAssistantStore } from '@/stores/assistant'
14+
import { useRouter } from 'vue-router'
1415
// import { i18n } from '@/i18n'
1516
// const t = i18n.global.t
1617
const assistantStore = useAssistantStore()
1718
const { wsCache } = useCache()
19+
const router = useRouter()
1820
// Response data structure
1921
export interface ApiResponse<T = unknown> {
2022
code: number
@@ -193,6 +195,15 @@ class HttpService {
193195
? error.response.data.toString()
194196
: 'Unauthorized, please login again'
195197
// Redirect to login page if needed
198+
if (assistantStore.getAssistant) {
199+
wsCache.delete('user.token')
200+
if (router?.push) {
201+
router.push(`/401?title=${encodeURIComponent(errorMessage)}`)
202+
} else {
203+
window.location.href = `/#/401?title=${encodeURIComponent(errorMessage)}`
204+
}
205+
return
206+
}
196207
ElMessage({
197208
message: errorMessage,
198209
type: 'error',

frontend/src/views/error/index.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div class="page-not-found">
3+
<Icon name="401"><Four class="svg-icon login-logo-icon" /></Icon>
4+
<span class="span-403">{{ title || routerTitle || '' }}</span>
5+
</div>
6+
</template>
7+
8+
<script lang="ts" setup>
9+
import Four from '@/assets/svg/401.svg'
10+
import { Icon } from '@/components/icon-custom'
11+
import { propTypes } from '@/utils/propTypes'
12+
import { computed } from 'vue'
13+
import { useRoute } from 'vue-router'
14+
const route = useRoute()
15+
defineProps({
16+
title: propTypes.string,
17+
})
18+
const routerTitle = computed(() => route.query?.title || '')
19+
</script>
20+
<style lang="less">
21+
.page-not-found {
22+
height: 100px;
23+
width: 100%;
24+
top: calc(50% - 100px);
25+
position: absolute;
26+
text-align: center;
27+
}
28+
.span-403 {
29+
display: block;
30+
margin: 0;
31+
font-size: var(--ed-font-size-base);
32+
color: var(--ed-text-color-secondary);
33+
}
34+
</style>

0 commit comments

Comments
 (0)