From e40ed227465c44923c02348dc663f20ad132878f Mon Sep 17 00:00:00 2001 From: Hannah dagemark Date: Tue, 15 Sep 2026 11:22:37 +0200 Subject: [PATCH] Fix the login auth --- app/api/users/login/route.ts | 15 ++++++++++++--- lib/api/helpers/users.ts | 4 ++++ lib/server_functions/userAuth.ts | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/api/users/login/route.ts b/app/api/users/login/route.ts index 99226cf..9e9ef28 100644 --- a/app/api/users/login/route.ts +++ b/app/api/users/login/route.ts @@ -1,15 +1,24 @@ const BACKEND_URL = process.env.BACKEND_URL; export async function POST(request: Request) { + const indata = await request.json(); + const body = new URLSearchParams({ + username: indata.username, + password: indata.password, + }); + console.log(`recieved users/login call with data: ${body}`); const response = await fetch(`${BACKEND_URL}/users/auth`, { method: "POST", - headers: request.headers, - body: request.body, - duplex: "half", + body: body, + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, }); const data = await response.json(); + console.log(`Recieved data from user auth fetch data as ${data}`); + return Response.json(data, { status: response.status, }); diff --git a/lib/api/helpers/users.ts b/lib/api/helpers/users.ts index fc925f4..eaccf9c 100644 --- a/lib/api/helpers/users.ts +++ b/lib/api/helpers/users.ts @@ -20,6 +20,10 @@ export async function getUser(id: number) { } export async function loginUser(user: FormData) { + console.log(`Recieved login user request for form: `); + for (const value of user.values()) { + console.log(value); + } const body = { username: user.get("username"), password: user.get("password"), diff --git a/lib/server_functions/userAuth.ts b/lib/server_functions/userAuth.ts index 538c665..3dac74b 100644 --- a/lib/server_functions/userAuth.ts +++ b/lib/server_functions/userAuth.ts @@ -8,6 +8,7 @@ import { Token } from "../api/types"; export async function login(formData: FormData) { "use server"; const token = await loginUser(formData); + console.log(`Fetched following token for login: ${token}`); await createSession(token); redirect("/Admin/Overview"); }