Skip to content

Commit

Permalink
fix(ui/sidebar): disable admin password check dialog in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Aug 28, 2024
1 parent adcb75a commit f1a86d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ui/artalk-sidebar/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ function syncArtalk(artalk: Artalk) {
const artalkUser = artalk.ctx.get('user')
const artalkUserData = artalkUser.getData()
const logout = () => {
user.logout()
nextTick(() => {
router.replace('/login')
})
}
// Remove login failed dialog if sidebar
artalk.ctx.getApiHandlers().remove('need_login')
artalk.ctx.getApiHandlers().add('need_login', async () => {
logout()
throw new Error('Need login')
})
// Check user status
artalk.ctx
.getApi()
.user.getUserStatus({
Expand All @@ -56,10 +71,7 @@ function syncArtalk(artalk: Artalk) {
})
.then((res) => {
if (res.data.is_admin && !res.data.is_login) {
user.logout()
nextTick(() => {
router.replace('/login')
})
logout()
} else {
// 将全部通知标记为已读
artalk.ctx.getApi().notifies.markAllNotifyRead({
Expand Down
5 changes: 5 additions & 0 deletions ui/artalk/src/api/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ApiHandlers {
action: T,
handler: (data: ApiHandlerPayload[T]) => Promise<void>,
) => void
remove: (action: PayloadKey) => void
get: () => ApiHandler[]
}

Expand All @@ -25,6 +26,10 @@ export function createApiHandlers(): ApiHandlers {
add: (action, handler) => {
handlers.push({ action, handler })
},
remove: (action) => {
const index = handlers.findIndex((h) => h.action === action)
if (index !== -1) handlers.splice(index, 1)
},
get: () => handlers,
}
}

0 comments on commit f1a86d5

Please sign in to comment.