refactor: use middleware to handle redirection

This commit is contained in:
Anthony Fu 2022-11-15 21:54:13 +08:00
parent a17d3276d3
commit 0dac7b9785
3 changed files with 15 additions and 13 deletions

8
middleware/auth.ts Normal file
View file

@ -0,0 +1,8 @@
export default defineNuxtRouteMiddleware((from) => {
const token = useCookie('nuxtodon-token')
if (!token.value)
return navigateTo('/public')
else if (from.path === '/')
return navigateTo('/home')
})