fix: handle permalinks with app shell (#468)

pull/474/head
Daniel Roe 2022-12-20 08:20:40 +00:00 zatwierdzone przez GitHub
rodzic f8ebc0e99a
commit 8de1c95fd3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 11 dodań i 3 usunięć

Wyświetl plik

@ -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,

Wyświetl plik

@ -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])

Wyświetl plik

@ -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)
})
}