diff --git a/composables/users.ts b/composables/users.ts index 5ec06be4..1118d211 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -85,7 +85,7 @@ export async function loginTo(user?: Omit & { account?: Ac } } - if ('server' in route.params && user?.token) { + if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) { await router.push({ ...route, force: true, diff --git a/middleware/permalink.global.ts b/middleware/permalink.global.ts index 167d0cc2..89e5426d 100644 --- a/middleware/permalink.global.ts +++ b/middleware/permalink.global.ts @@ -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]) diff --git a/plugins/masto.ts b/plugins/masto.ts index 0865330a..e2540fc6 100644 --- a/plugins/masto.ts +++ b/plugins/masto.ts @@ -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) }) }