From a65590d47ed472edc34a9daa2297059daff312a8 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: Sat, 16 Mar 2024 21:09:06 -0400 Subject: [PATCH] refactor(client-side): use `to` parameter to check for current url + associated params --- lib/client/middleware.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/client/middleware.ts b/lib/client/middleware.ts index 5cc6dae..d94647c 100644 --- a/lib/client/middleware.ts +++ b/lib/client/middleware.ts @@ -26,8 +26,7 @@ export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { export const storyEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { const { data: curU } = useAuth(); - const rtr = useRoute(); - const { data: storyInfo } = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${rtr.params.id}/full`); + const { data: storyInfo } = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${to.params.id}/full`); if (!storyInfo.value) show404(); if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { return showError({ @@ -38,8 +37,7 @@ export const storyEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => }); export const draftEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { const { data: curU } = useAuth(); - const rtr = useRoute(); - const { data: storyInfo } = await useApiFetch(`/draft/${rtr.params.id}`); + const { data: storyInfo } = await useApiFetch(`/draft/${to.params.id}`); if (!storyInfo.value) show404(); if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { return showError({