WIP: Major Update 0.2 #3

Draft
Hannah wants to merge 19 commits from Devbranch into main
3 changed files with 17 additions and 3 deletions
Showing only changes of commit e40ed22746 - Show all commits

Fix the login auth

Hannah dagemark 2026-09-15 11:22:37 +02:00

View file

@ -1,15 +1,24 @@
const BACKEND_URL = process.env.BACKEND_URL; const BACKEND_URL = process.env.BACKEND_URL;
export async function POST(request: Request) { 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`, { const response = await fetch(`${BACKEND_URL}/users/auth`, {
method: "POST", method: "POST",
headers: request.headers, body: body,
body: request.body, headers: {
duplex: "half", "Content-Type": "application/x-www-form-urlencoded",
},
}); });
const data = await response.json(); const data = await response.json();
console.log(`Recieved data from user auth fetch data as ${data}`);
return Response.json(data, { return Response.json(data, {
status: response.status, status: response.status,
}); });

View file

@ -20,6 +20,10 @@ export async function getUser(id: number) {
} }
export async function loginUser(user: FormData) { 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 = { const body = {
username: user.get("username"), username: user.get("username"),
password: user.get("password"), password: user.get("password"),

View file

@ -8,6 +8,7 @@ import { Token } from "../api/types";
export async function login(formData: FormData) { export async function login(formData: FormData) {
"use server"; "use server";
const token = await loginUser(formData); const token = await loginUser(formData);
console.log(`Fetched following token for login: ${token}`);
await createSession(token); await createSession(token);
redirect("/Admin/Overview"); redirect("/Admin/Overview");
} }