import type { APIRoute } from "astro"; export const POST: APIRoute = async ({ request, cookies }) => { const reqBody = await request.text(); if (!reqBody) throw new Error("body not found"); const res = await fetch(`${import.meta.env.API_URL}/accounts/login`, { method: "POST", body: reqBody, headers: { "Content-Type": "application/json", }, }); const resBody = await res.text(); const resBodyJson = JSON.parse(resBody); if (res.status === 201 && resBodyJson?.jwt) { cookies.set("jwt", resBodyJson.jwt, { secure: true, httpOnly: true, path: "/", sameSite: "strict", }); } return new Response(resBody, { status: res.status }); };