From b980d519d5654f1f852b7a0eeb9adb13e22606a4 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 18:09:15 +0800 Subject: [PATCH] fix: router --- components/user/UserSignIn.vue | 5 +++-- composables/users.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/user/UserSignIn.vue b/components/user/UserSignIn.vue index 5798c8a5..678290a8 100644 --- a/components/user/UserSignIn.vue +++ b/components/user/UserSignIn.vue @@ -47,8 +47,9 @@ async function oauth() { } } -function explore() { - masto.loginTo({ server, guestOnly: true }) +async function explore() { + await masto.loginTo({ server, guest: true }) + isSigninDialogOpen.value = false } async function handleInput() { diff --git a/composables/users.ts b/composables/users.ts index 902a0c3d..04853b70 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -89,6 +89,8 @@ async function loginTo({ server, token, vapidKey, pushSubscription, guest = fals const route = useRoute() const router = useRouter() + const oldServer = currentUser.value.server + let user: UserLogin | undefined = token ? users.value.find(u => u.server === server && u.token === token) : ((guest @@ -150,11 +152,17 @@ async function loginTo({ server, token, vapidKey, pushSubscription, guest = fals currentUserId.value = getUniqueUserId(user) // This only cleans up the URL; page content should stay the same - if (route.path === '/signin/callback') { + if (!user.guest && (route.path === '/signin/callback' || route.path === '/')) { await router.push('/home') } - + else if (isGuest.value && route.meta.middleware === 'auth') { + await router.push(`/${server}/public`) + } else if ('server' in route.params && user.server !== route.params.server) { + if (!route.params.account.includes('@')) + // convert to long handle + route.params.account += `@${oldServer}` + await router.push({ ...route, params: {