fix: handle permalinks with app shell (#468)

zio/stable
Daniel Roe 2022-12-20 08:20:40 +00:00 committed by GitHub
parent f8ebc0e99a
commit 8de1c95fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -85,7 +85,7 @@ export async function loginTo(user?: Omit<UserLogin, 'account'> & { account?: Ac
}
}
if ('server' in route.params && user?.token) {
if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) {
await router.push({
...route,
force: true,

View File

@ -1,4 +1,7 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
if (process.server)
return
// Skip running middleware before masto has been initialised
if (!useNuxtApp().$masto)
return
@ -44,8 +47,12 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
return getAccountRoute(account)
}
const masto = useMasto()
if (!masto.loggedIn.value)
await masto.loginTo(currentUser.value)
// If we're logged in, search for the local id the account or status corresponds to
const { value } = await useMasto().search({ q: `https:/${to.fullPath}`, resolve: true, limit: 1 }).next()
const { value } = await masto.search({ q: `https:/${to.fullPath}`, resolve: true, limit: 1 }).next()
const { accounts, statuses } = value
if (statuses[0])

View File

@ -53,7 +53,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
nuxtApp.hook('app:suspense:resolve', () => {
// TODO: improve upstream to make this synchronous (delayed auth)
masto.loginTo(user)
if (!masto.loggedIn.value)
masto.loginTo(user)
})
}