diff --git a/lib/server/middlewareButNotReally/isLoggedIn.ts b/lib/server/middlewareButNotReally/isLoggedIn.ts index e570cba..345a85d 100644 --- a/lib/server/middlewareButNotReally/isLoggedIn.ts +++ b/lib/server/middlewareButNotReally/isLoggedIn.ts @@ -1,9 +1,10 @@ import { H3Event, EventHandlerRequest } from "h3"; +import { messages } from "../constants"; export default function (ev: H3Event) { if (!ev.context.currentUser) { throw createError({ statusCode: 401, - statusMessage: "Authentication required", + statusMessage: messages[401], }); } } diff --git a/lib/server/middlewareButNotReally/storyCheck.ts b/lib/server/middlewareButNotReally/storyCheck.ts index a023c79..cfe3dcc 100644 --- a/lib/server/middlewareButNotReally/storyCheck.ts +++ b/lib/server/middlewareButNotReally/storyCheck.ts @@ -2,6 +2,7 @@ import type { H3Event, EventHandlerRequest } from "h3"; import type { Document } from "mongoose"; import { isFicmasHidden } from "~/lib/functions"; import { IStory } from "~/models/stories"; +import { messages } from "../constants"; export default async function ( event: H3Event, story: IStory, @@ -18,11 +19,11 @@ export default async function ( } if ( story.chapters[num]?.hidden || - (event.context.currentUser._id !== story.author._id && - !event.context.currentUser.isAdmin) + (event.context.currentUser?._id !== story.author._id && + !event.context.currentUser?.profile.isAdmin) ) { ret.statusCode = 403; - ret.message = "Forbidden"; + ret.message = messages[403]; } return !!Object.keys(ret).length ? ret : null; }