Skip to content

Commit f1a86d5

Browse files
committed
fix(ui/sidebar): disable admin password check dialog in sidebar
1 parent adcb75a commit f1a86d5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

ui/artalk-sidebar/src/App.vue

+16-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ function syncArtalk(artalk: Artalk) {
4848
const artalkUser = artalk.ctx.get('user')
4949
const artalkUserData = artalkUser.getData()
5050
51+
const logout = () => {
52+
user.logout()
53+
nextTick(() => {
54+
router.replace('/login')
55+
})
56+
}
57+
58+
// Remove login failed dialog if sidebar
59+
artalk.ctx.getApiHandlers().remove('need_login')
60+
artalk.ctx.getApiHandlers().add('need_login', async () => {
61+
logout()
62+
throw new Error('Need login')
63+
})
64+
65+
// Check user status
5166
artalk.ctx
5267
.getApi()
5368
.user.getUserStatus({
@@ -56,10 +71,7 @@ function syncArtalk(artalk: Artalk) {
5671
})
5772
.then((res) => {
5873
if (res.data.is_admin && !res.data.is_login) {
59-
user.logout()
60-
nextTick(() => {
61-
router.replace('/login')
62-
})
74+
logout()
6375
} else {
6476
// 将全部通知标记为已读
6577
artalk.ctx.getApi().notifies.markAllNotifyRead({

ui/artalk/src/api/handler.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ApiHandlers {
1616
action: T,
1717
handler: (data: ApiHandlerPayload[T]) => Promise<void>,
1818
) => void
19+
remove: (action: PayloadKey) => void
1920
get: () => ApiHandler[]
2021
}
2122

@@ -25,6 +26,10 @@ export function createApiHandlers(): ApiHandlers {
2526
add: (action, handler) => {
2627
handlers.push({ action, handler })
2728
},
29+
remove: (action) => {
30+
const index = handlers.findIndex((h) => h.action === action)
31+
if (index !== -1) handlers.splice(index, 1)
32+
},
2833
get: () => handlers,
2934
}
3035
}

0 commit comments

Comments
 (0)