From 72855d7725f18006293614a82c12d9935335affa Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 26 Dec 2022 08:33:14 +0100 Subject: [PATCH] refactor: move post-login push logic to single place --- composables/users.ts | 7 ++++++- plugins/masto.ts | 12 +++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/composables/users.ts b/composables/users.ts index ffe98b25..73c4f3f3 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -88,7 +88,12 @@ async function loginTo(user?: Omit & { account?: AccountCr } } - if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) { + // This only cleans up the URL; page content should stay the same + if (route.path === '/signin/callback') { + await router.push('/home') + } + + else if ('server' in route.params && user?.token && !useNuxtApp()._processingMiddleware) { await router.push({ ...route, force: true, diff --git a/plugins/masto.ts b/plugins/masto.ts index a3cecbed..1fd0ac5b 100644 --- a/plugins/masto.ts +++ b/plugins/masto.ts @@ -2,8 +2,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { const masto = createMasto() if (process.client) { - const { query, path } = useRoute() - const router = useRouter() + const { query } = useRoute() const user = typeof query.server === 'string' && typeof query.token === 'string' ? { server: query.server, @@ -14,13 +13,8 @@ export default defineNuxtPlugin(async (nuxtApp) => { nuxtApp.hook('app:suspense:resolve', () => { // TODO: improve upstream to make this synchronous (delayed auth) - if (!masto.loggedIn.value) { - masto.loginTo(user).then(() => { - // This only cleans up the URL; page content should stay the same - if (path === '/signin/callback') - router.push('/home') - }) - } + if (!masto.loggedIn.value) + masto.loginTo(user) }) }