Skip to content

Commit

Permalink
fix(ui/sidebar): unable to logout if user is not admin in control center
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed May 24, 2024
1 parent 824f122 commit fdfeef8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
18 changes: 16 additions & 2 deletions ui/artalk-sidebar/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import MD5 from '../lib/md5'
import { storeToRefs } from 'pinia'
import { useUserStore } from '../stores/user'
import { useNavStore } from '../stores/nav'
import { artalk } from '../global'
import { artalk, isOpenFromSidebar } from '../global'
const nav = useNavStore()
const router = useRouter()
const user = useUserStore()
const { t } = useI18n()
const { site: curtSite, isAdmin, email } = storeToRefs(user)
Expand All @@ -16,6 +17,19 @@ const userAvatarImgURL = computed(() => {
if (!conf) return ``
return `${conf.mirror.replace(/\/$/, '')}/${MD5(email.value)}?${conf.params.replace(/^\?/, '')}`
})
const avatarClickHandler = () => {
if (!isOpenFromSidebar()) logout()
}
const logout = () => {
if (!window.confirm(t('logoutConfirm'))) return
useUserStore().logout()
nextTick(() => {
router.replace('/login')
})
}
</script>

<template>
Expand All @@ -30,7 +44,7 @@ const userAvatarImgURL = computed(() => {
</div>
</template>
<template v-else>
<div class="avatar">
<div class="avatar" @click="avatarClickHandler">
<img :src="userAvatarImgURL" />
</div>
</template>
Expand Down
6 changes: 4 additions & 2 deletions ui/artalk-sidebar/src/components/SiteSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { storeToRefs } from 'pinia'
import { useNavStore } from '../stores/nav'
import { useUserStore } from '../stores/user'
import { bootParams } from '@/global'
import { isOpenFromSidebar } from '@/global'
const el = ref<HTMLElement | null>(null)
Expand Down Expand Up @@ -69,6 +69,8 @@ watch(curtShow, (value) => {
})
function logout() {
if (!window.confirm(t('logoutConfirm'))) return
useUserStore().logout()
nextTick(() => {
router.replace('/login')
Expand All @@ -92,7 +94,7 @@ function logout() {
</div>

<!-- Logout Button -->
<div v-if="!bootParams.user?.email" class="atk-site-item" @click="logout()">
<div v-if="!isOpenFromSidebar()" class="atk-site-item" @click="logout()">
<svg
class="atk-site-logo"
stroke="currentColor"
Expand Down
4 changes: 4 additions & 0 deletions ui/artalk-sidebar/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ export function initArtalk() {
},
})
}

export function isOpenFromSidebar() {
return !!bootParams.user?.email
}
3 changes: 3 additions & 0 deletions ui/artalk-sidebar/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const en = {
loginFailure: 'Login failure',
login: 'Login',
logout: 'Logout',
logoutConfirm: 'Are you sure you want to log out?',
loginSelectHint: 'Please select the account you wish to log into:',
}

Expand Down Expand Up @@ -159,6 +160,7 @@ const zhCN: typeof en = {
loginFailure: '登录发生异常',
login: '登录',
logout: '退出登录',
logoutConfirm: '确定要退出登录吗?',
loginSelectHint: '请选择您要登录的账户:',
}

Expand Down Expand Up @@ -241,6 +243,7 @@ const zhTW: typeof en = {
loginFailure: '登入失敗',
login: '登入',
logout: '登出',
logoutConfirm: '確定要登出嗎?',
loginSelectHint: '請選擇您要登入的帳號:',
}

Expand Down

0 comments on commit fdfeef8

Please sign in to comment.