mirror of
https://github.com/elk-zone/elk
synced 2024-11-27 06:18:07 +09:00
refactor: use middleware to handle redirection
This commit is contained in:
parent
a17d3276d3
commit
0dac7b9785
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">
|
||||
const token = useCookie('nuxtodon-token')
|
||||
const router = useRouter()
|
||||
if (!token.value)
|
||||
router.replace('/public')
|
||||
definePageMeta({
|
||||
middleware: 'auth',
|
||||
})
|
||||
|
||||
const masto = await useMasto()
|
||||
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 />
|
||||
</template>
|
||||
<slot>
|
||||
<TimelinePaginator :timelines="paginator" />
|
||||
<TimelinePaginator :paginator="paginator" />
|
||||
</slot>
|
||||
</MainContent>
|
||||
</template>
|
||||
|
@ -1,12 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
const token = useCookie('nuxtodon-token')
|
||||
const router = useRouter()
|
||||
|
||||
// TODO: move to middleware
|
||||
if (!token.value)
|
||||
router.replace('/public')
|
||||
else
|
||||
router.replace('/home')
|
||||
definePageMeta({
|
||||
middleware: 'auth',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
Loading…
Reference in New Issue
Block a user