diff --git a/server/middleware/auth.ts b/server/middleware/auth.ts index cb16180..82760c6 100644 --- a/server/middleware/auth.ts +++ b/server/middleware/auth.ts @@ -8,6 +8,7 @@ const endpointsWithoutAuth: string[] = [ "/hi", "/login", "/logout", + "/firstRun", ]; export default defineEventHandler(async (e) => { @@ -31,10 +32,14 @@ export default defineEventHandler(async (e) => { */ export async function isAuthorised(token: string | undefined): Promise { if (!token) return false; - const [[session]] = await database.query( - "SELECT EXISTS(SELECT `id` FROM `sessions` WHERE `id` = ? AND `expiry_date` >= NOW()) as `logged_in`", - [token], - ) as unknown as data<{logged_in: number}>; + try { + const [[session]] = await database.query( + "SELECT EXISTS(SELECT `id` FROM `sessions` WHERE `id` = ? AND `expiry_date` >= NOW()) as `logged_in`", + [token], + ) as unknown as data<{logged_in: number}>; - return session.logged_in === 1; + return session.logged_in === 1; + } catch { + return false; + } }