forked from Mirrors/elk
fix: handle permalinks with app shell (#468)
This commit is contained in:
parent
f8ebc0e99a
commit
8de1c95fd3
3 changed files with 11 additions and 3 deletions
|
@ -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({
|
await router.push({
|
||||||
...route,
|
...route,
|
||||||
force: true,
|
force: true,
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
|
if (process.server)
|
||||||
|
return
|
||||||
|
|
||||||
// Skip running middleware before masto has been initialised
|
// Skip running middleware before masto has been initialised
|
||||||
if (!useNuxtApp().$masto)
|
if (!useNuxtApp().$masto)
|
||||||
return
|
return
|
||||||
|
@ -44,8 +47,12 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
return getAccountRoute(account)
|
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
|
// 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
|
const { accounts, statuses } = value
|
||||||
if (statuses[0])
|
if (statuses[0])
|
||||||
|
|
|
@ -53,7 +53,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
|
|
||||||
nuxtApp.hook('app:suspense:resolve', () => {
|
nuxtApp.hook('app:suspense:resolve', () => {
|
||||||
// TODO: improve upstream to make this synchronous (delayed auth)
|
// TODO: improve upstream to make this synchronous (delayed auth)
|
||||||
masto.loginTo(user)
|
if (!masto.loggedIn.value)
|
||||||
|
masto.loginTo(user)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue