diff --git a/lib/client/middleware.ts b/lib/client/middleware.ts new file mode 100644 index 0000000..ec32a45 --- /dev/null +++ b/lib/client/middleware.ts @@ -0,0 +1,15 @@ +import { SingleChapterResult } from "./types/slightlyDifferentStory"; + +export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { + const { getSession } = useAuth(); + await getSession({ force: true }); + const { data } = useAuth(); + console.log("to n from", to, from, data); + const { data: story, error } = await useApiFetch( + to.path, + ); + console.log("fns", story, error); + if (!data?.value?.user && story.value?.currentChapter.loggedInOnly) { + return navigateTo("/login"); + } +});