29 lines
723 B
Vue
29 lines
723 B
Vue
|
<template><p></p></template>
|
||
|
|
||
|
<script setup lang="ts">
|
||
|
import { onBeforeRouteUpdate, useRouter } from 'vue-router';
|
||
|
import { inject, onBeforeMount } from 'vue';
|
||
|
import { check_token, get_root, isErrorResponse, TokenInjectType } from '@/api';
|
||
|
|
||
|
const router = useRouter();
|
||
|
const jwt = inject<TokenInjectType>('jwt') as TokenInjectType;
|
||
|
|
||
|
async function start_redirect() {
|
||
|
const token = await check_token(jwt);
|
||
|
if (!token) return;
|
||
|
const root = await get_root(token);
|
||
|
if (isErrorResponse(root)) return jwt.logout();
|
||
|
await router.push({
|
||
|
name: 'fs',
|
||
|
params: { node_id: root.rootId }
|
||
|
});
|
||
|
}
|
||
|
|
||
|
onBeforeRouteUpdate(async () => {
|
||
|
await start_redirect();
|
||
|
});
|
||
|
onBeforeMount(async () => {
|
||
|
await start_redirect();
|
||
|
});
|
||
|
</script>
|