fix(client-side): add error check to story redirect middleware
This commit is contained in:
parent
da3beefa6f
commit
a5346e8622
@ -1,4 +1,7 @@
|
|||||||
import { SingleChapterResult } from "./types/slightlyDifferentStory";
|
import { SingleChapterResult } from "./types/slightlyDifferentStory";
|
||||||
|
import { IChapter } from "~/models/stories/chapter";
|
||||||
|
import { IStory } from "~/models/stories";
|
||||||
|
import { messages } from "~/lib/server/constants";
|
||||||
|
|
||||||
export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => {
|
export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
const { getSession } = useAuth();
|
const { getSession } = useAuth();
|
||||||
@ -8,6 +11,11 @@ export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => {
|
|||||||
const { data: story, error } = await useApiFetch<SingleChapterResult>(
|
const { data: story, error } = await useApiFetch<SingleChapterResult>(
|
||||||
to.path,
|
to.path,
|
||||||
);
|
);
|
||||||
|
if (error.value) {
|
||||||
|
return showError(error.value);
|
||||||
|
} else if (!story.value) {
|
||||||
|
return showError({ statusCode: 404, message: messages[404] });
|
||||||
|
}
|
||||||
console.log("fns", story, error);
|
console.log("fns", story, error);
|
||||||
if (!data?.value?.user && story.value?.currentChapter.loggedInOnly) {
|
if (!data?.value?.user && story.value?.currentChapter.loggedInOnly) {
|
||||||
return navigateTo("/login");
|
return navigateTo("/login");
|
||||||
|
Loading…
Reference in New Issue
Block a user