16 lines
490 B
TypeScript
16 lines
490 B
TypeScript
|
import queryStory from "~/lib/server/dbHelpers/storyQuerier";
|
||
|
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
|
||
|
export default eventHandler(async (ev) => {
|
||
|
const story = await queryStory(ev);
|
||
|
let chrs = await storyCheck(ev, story);
|
||
|
if (chrs != null) {
|
||
|
throw createError(chrs);
|
||
|
}
|
||
|
if (story.chapters.some((a) => a.loggedInOnly) && !ev.context.currentUser)
|
||
|
throw createError({
|
||
|
statusCode: 401,
|
||
|
message: "Authentication required",
|
||
|
});
|
||
|
return story;
|
||
|
});
|