Skip to content

Commit b299ef0

Browse files
authored
fix: Page optimization when the application is unavailable (#3580)
1 parent ea56fd6 commit b299ef0

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

apps/chat/serializers/chat_authentication.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def profile(self):
5757
self.is_valid(raise_exception=True)
5858
access_token = self.data.get("access_token")
5959
application_access_token = QuerySet(ApplicationAccessToken).filter(access_token=access_token).first()
60+
if application_access_token is None:
61+
raise NotFound404(404, _("Invalid access_token"))
6062
application_id = application_access_token.application_id
6163
profile = {
6264
'authentication': False

ui/src/router/chat/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ router.beforeEach(
3737
try {
3838
authentication = await chatUser.isAuthentication()
3939
} catch (e: any) {
40-
next({
41-
path: '/404',
42-
})
40+
next()
4341
return
4442
}
4543
const p_token = to.query.token
@@ -86,7 +84,12 @@ router.beforeEach(
8684
}
8785
}
8886
} else {
89-
await chatUser.anonymousAuthentication()
87+
try {
88+
await chatUser.anonymousAuthentication()
89+
} catch (e: any) {
90+
next()
91+
return
92+
}
9093
}
9194
if (!chatUser.application) {
9295
try {

ui/src/views/chat/index.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ const {
2525
2626
const currentTemplate = computed(() => {
2727
let modeName = ''
28-
if (!mode || mode === 'pc') {
29-
modeName = common.isMobile() ? 'mobile' : 'pc'
28+
if (chatUser.application) {
29+
if (!mode || mode === 'pc') {
30+
modeName = common.isMobile() ? 'mobile' : 'pc'
31+
} else {
32+
modeName = mode
33+
}
3034
} else {
31-
modeName = mode
35+
modeName = 'no-service'
3236
}
37+
3338
const name = `/src/views/chat/${modeName}/index.vue`
3439
return components[name].default
3540
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="not-found-container flex-center">
3+
<div>
4+
<img src="@/assets/500.png" width="250" alt="" />
5+
<h4 class="text-center">{{ $t('common.notFound.NoService') }}</h4>
6+
</div>
7+
</div>
8+
</template>
9+
<script setup lang="ts">
10+
import { useRouter } from 'vue-router'
11+
const router = useRouter()
12+
</script>
13+
<style lang="scss" scoped>
14+
.not-found-container {
15+
height: 100vh;
16+
width: 100vw;
17+
}
18+
</style>

0 commit comments

Comments
 (0)