From b62d101a88d830adb50647040e5f1db4f4304002 Mon Sep 17 00:00:00 2001 From: CnF-Gris Date: Mon, 30 Jun 2025 20:06:30 +0000 Subject: [PATCH] Fixed bugs and added logging --- src/routes/api/login/+server.ts | 9 ++++++--- src/routes/api/register/+server.ts | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/routes/api/login/+server.ts b/src/routes/api/login/+server.ts index 4a70f0b..79efa49 100644 --- a/src/routes/api/login/+server.ts +++ b/src/routes/api/login/+server.ts @@ -3,6 +3,7 @@ import type { RequestHandler } from './$types'; import { UserApp } from '$lib/classes/users'; import { SessionApp } from '$lib/classes/sessions'; import { AppData } from '$lib/classes/app-sessions'; +import { logger } from '$lib/utils/logger'; /*********************************************************** * @@ -19,6 +20,8 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { const local: App.Locals = locals const cookie: Cookies = cookies + logger.debug(`locals: ${local.session}`, "API Login") + const session = local.session if (session) { @@ -32,7 +35,7 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { let tmpJSON: any try { - const tmpJson = await req.json() + tmpJSON = await req.json() } catch { return error(400, "Bad Request") } @@ -57,7 +60,7 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { user.userID ) - // Iw we have no session, then probably a 500? + // If we have no session, then probably a 500? if (!oldSession) { return error(500, "Internal Server Error") } @@ -74,7 +77,7 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { path: "/" } ) - + return text("OK") } diff --git a/src/routes/api/register/+server.ts b/src/routes/api/register/+server.ts index 8ae0abc..aee2f58 100644 --- a/src/routes/api/register/+server.ts +++ b/src/routes/api/register/+server.ts @@ -3,6 +3,7 @@ import type { RequestHandler } from './$types'; import { UserApp, User } from '$lib/classes/users'; import { SessionApp, Session } from '$lib/classes/sessions'; import { AppData } from '$lib/classes/app-sessions'; +import { logger } from '$lib/utils/logger'; /*********************************************************** * @@ -32,7 +33,7 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { let tmpJSON: any try { - const tmpJson = await req.json() + tmpJSON = await req.json() } catch { return error(400, "Bad Request") } @@ -60,7 +61,8 @@ export const POST: RequestHandler = async ({ request, locals, cookies }) => { newSession = SessionApp.createSessionFromUserID( user.userID ) - } catch { + } catch(err){ + logger.debug(`error: ${err}`, "API Register") return error(500, "Internal Server Error") }