mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
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({
|
||||
...route,
|
||||
force: true,
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue