2024-08-05 14:38:44 +02:00
|
|
|
import type { Actions } from "./$types";
|
|
|
|
|
|
|
|
|
|
export const actions: Actions = {
|
2024-07-31 07:23:32 +02:00
|
|
|
default: async ({ request, cookies, fetch }) => {
|
|
|
|
|
const data = await request.formData();
|
|
|
|
|
|
|
|
|
|
const res = await fetch("http://localhost:3000/rpc/login", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
username: data.get("username"),
|
|
|
|
|
password: data.get("password")
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await res.json();
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
return { success: false, message: response.message };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cookies.set("session_token", response.token, { path: "/" });
|
2024-08-01 18:09:35 +02:00
|
|
|
return { success: true, message: "Successfully logged in" };
|
2024-07-31 07:23:32 +02:00
|
|
|
}
|
|
|
|
|
};
|