36 lines
1.2 KiB
Vue
36 lines
1.2 KiB
Vue
<script setup>
|
|
import { computed, onMounted, onBeforeUnmount } from "vue";
|
|
import { useRoute } from "#app";
|
|
import { NuxtLayout, NuxtPage, NuxtRouteAnnouncer } from "#components";
|
|
import BuildUpdateNotice from "~/components/BuildUpdateNotice.vue";
|
|
import OperationToasts from "~/components/OperationToasts.vue";
|
|
import { useAuth } from "~/lib/auth.js";
|
|
import { t as useTheme } from "~/lib/useTheme.js";
|
|
import { isPublicShop, isAuthPage, isPublicRoute } from "~/utils/access.js";
|
|
|
|
const auth = useAuth();
|
|
const route = useRoute();
|
|
const theme = useTheme();
|
|
const layout = computed(() =>
|
|
!auth.isLoggedIn && isPublicShop(route) ? "public-order" : route.meta.layout,
|
|
);
|
|
// An authenticated route's component tree belongs to that session, not to a pending redirect.
|
|
const canRenderRoute = computed(() => auth.isLoggedIn || isPublicRoute(route));
|
|
const routeSessionKey = computed(() =>
|
|
isAuthPage(route.path) || route.path === "/home.htm"
|
|
? route.path
|
|
: auth.token || "anonymous",
|
|
);
|
|
onMounted(theme.init);
|
|
onBeforeUnmount(theme.dispose);
|
|
</script>
|
|
|
|
<template>
|
|
<NuxtRouteAnnouncer />
|
|
<BuildUpdateNotice />
|
|
<OperationToasts />
|
|
<NuxtLayout v-if="canRenderRoute" :key="routeSessionKey" :name="layout"
|
|
><NuxtPage
|
|
/></NuxtLayout>
|
|
</template>
|