Skip to content

Commit

Permalink
fix: sign-out and empty content (#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Feb 6, 2023
1 parent 6e7ac24 commit f7a8d47
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import type { RouteLocationNormalized } from 'vue-router'

export default defineNuxtRouteMiddleware((to) => {
if (process.server)
return

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

0 comments on commit f7a8d47

Please sign in to comment.