forked from Mirrors/elk
refactor: use middleware to handle redirection
This commit is contained in:
parent
a17d3276d3
commit
0dac7b9785
3 changed files with 15 additions and 13 deletions
8
middleware/auth.ts
Normal file
8
middleware/auth.ts
Normal 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')
|
||||||
|
})
|
|
@ -1,8 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const token = useCookie('nuxtodon-token')
|
definePageMeta({
|
||||||
const router = useRouter()
|
middleware: 'auth',
|
||||||
if (!token.value)
|
})
|
||||||
router.replace('/public')
|
|
||||||
|
|
||||||
const masto = await useMasto()
|
const masto = await useMasto()
|
||||||
const paginator = masto.timelines.getHomeIterable()
|
const paginator = masto.timelines.getHomeIterable()
|
||||||
|
@ -17,7 +16,7 @@ const paginator = masto.timelines.getHomeIterable()
|
||||||
<div color-gray i-ri:equalizer-fill mr-1 h-6 />
|
<div color-gray i-ri:equalizer-fill mr-1 h-6 />
|
||||||
</template>
|
</template>
|
||||||
<slot>
|
<slot>
|
||||||
<TimelinePaginator :timelines="paginator" />
|
<TimelinePaginator :paginator="paginator" />
|
||||||
</slot>
|
</slot>
|
||||||
</MainContent>
|
</MainContent>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const token = useCookie('nuxtodon-token')
|
definePageMeta({
|
||||||
const router = useRouter()
|
middleware: 'auth',
|
||||||
|
})
|
||||||
// TODO: move to middleware
|
|
||||||
if (!token.value)
|
|
||||||
router.replace('/public')
|
|
||||||
else
|
|
||||||
router.replace('/home')
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in a new issue