From 2b0d478ca7fcf9086a2df97b35b460d95c2b791f 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: Mon, 2 Oct 2023 16:20:13 -0400 Subject: [PATCH] feat(api): add `isLoggedIn` utility function for api routes which require authentication --- lib/server/middlewareButNotReally/isLoggedIn.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/server/middlewareButNotReally/isLoggedIn.ts diff --git a/lib/server/middlewareButNotReally/isLoggedIn.ts b/lib/server/middlewareButNotReally/isLoggedIn.ts new file mode 100644 index 0000000..e570cba --- /dev/null +++ b/lib/server/middlewareButNotReally/isLoggedIn.ts @@ -0,0 +1,9 @@ +import { H3Event, EventHandlerRequest } from "h3"; +export default function (ev: H3Event) { + if (!ev.context.currentUser) { + throw createError({ + statusCode: 401, + statusMessage: "Authentication required", + }); + } +}