From fe7c45223169423190018dd851e38bceab855051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 6 Dec 2023 22:19:05 -0500 Subject: [PATCH] feat(client-side): create story middleware redirect users to the login page if a story is restricted and they're not logged in --- lib/client/middleware.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/client/middleware.ts 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"); + } +});