From f7a8d471a6f491990e20395f59c0715a35bb3b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Mon, 6 Feb 2023 13:16:24 +0100 Subject: [PATCH] fix: sign-out and empty content (#1654) --- middleware/auth.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/middleware/auth.ts b/middleware/auth.ts index 40eafd80b5..d5e387656a 100644 --- a/middleware/auth.ts +++ b/middleware/auth.ts @@ -1,3 +1,5 @@ +import type { RouteLocationNormalized } from 'vue-router' + export default defineNuxtRouteMiddleware((to) => { if (process.server) return @@ -5,14 +7,19 @@ export default defineNuxtRouteMiddleware((to) => { if (to.path === '/signin/callback') return - onHydrated(() => { - if (!currentUser.value) { - if (to.path === '/home' && to.query['share-target'] !== undefined) - return navigateTo('/share-target') - else - return navigateTo(`/${currentServer.value}/public/local`) - } - if (to.path === '/') - return navigateTo('/home') - }) + if (isHydrated.value) + return handleAuth(to) + + onHydrated(() => handleAuth(to)) }) + +function handleAuth(to: RouteLocationNormalized) { + if (!currentUser.value) { + if (to.path === '/home' && to.query['share-target'] !== undefined) + return navigateTo('/share-target') + else + return navigateTo(`/${currentServer.value}/public/local`) + } + if (to.path === '/') + return navigateTo('/home') +}