fix: router

This commit is contained in:
三咲智子 2023-01-03 18:09:15 +08:00
parent 313cafa23c
commit b980d519d5
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
2 changed files with 13 additions and 4 deletions

View file

@ -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() {

View file

@ -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: {