From f7df0e54f51edcfae7eb6e7db5dadb56d1ff3153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 3 Jan 2023 10:29:58 +0800 Subject: [PATCH] fix: settings --- composables/users.ts | 12 +++++------- pages/settings.vue | 2 +- pages/settings/users/index.vue | 9 ++++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/composables/users.ts b/composables/users.ts index 2b077a76..883f01c8 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -44,7 +44,7 @@ const initializeUsers = async (): Promise | RemovableRef>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true }) const currentUserId = useLocalStorage(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '') -const isGuestId = computed(() => currentUserId.value.startsWith(`${GUEST_ID}@`)) +const isGuestId = computed(() => !currentUserId.value || currentUserId.value.startsWith(`${GUEST_ID}@`)) export const currentUser = computed(() => { if (!currentUserId.value) @@ -65,8 +65,9 @@ export const currentInstance = computed(() => { }) export const checkUser = (val: UserLogin | undefined): val is UserLogin => !!(val && !val.guest) export const isGuest = computed(() => !checkUser(currentUser.value)) +export const getUniqueUserId = (user: UserLogin) => user.guest ? `${GUEST_ID}@${user.server}` : user.account.id export const isSameUser = (a: UserLogin | undefined, b: UserLogin | undefined) => - a && b && a.server === b.server && a.token === b.token + a && b && getUniqueUserId(a) === getUniqueUserId(b) export const currentUserHandle = computed(() => isGuestId.value ? GUEST_ID : currentUser.value!.account!.acct @@ -216,11 +217,7 @@ export async function signout() { if (!currentUser.value) return - const masto = useMasto() - - const _currentUserId = currentUser.value.account!.id - - const index = users.value.findIndex(u => u.account?.id === _currentUserId) + const index = users.value.findIndex(u => isSameUser(u, currentUser.value)) if (index !== -1) { // Clear stale data @@ -244,6 +241,7 @@ export async function signout() { if (!currentUserId.value) await useRouter().push('/') + const masto = useMasto() await masto.loginTo(currentUser.value) } diff --git a/pages/settings.vue b/pages/settings.vue index 533369dd..9b6b5bd3 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -27,7 +27,7 @@ const isRootPath = computedEager(() => route.name === 'settings')
u.server === user.server && u.account.id === user.account.id)) + if (loggedInUsers.value.some(u => isSameUser(u, user))) continue newUsers.push(user) } @@ -69,8 +69,11 @@ async function importTokens() {