Files
place4bees.com/frontend/src/pages/konto/firma/dokument/[id].ts
T
torbinus 9b368f9b7a Firmenkunden-CRM mit B2B-Patenschaften und Firmenportal
Admin: Firmen mit Vertriebsstufe und Wiedervorlage, Ansprechpartner mit
Einladung ins Portal, B2B-Patenschaften mit Lieferungen und Neuigkeiten,
private Dokumente, Notizen und Anfragen.
Portal unter /konto/firma: Patenschaften, Lieferungen, Neuigkeiten,
Dokument-Download und Anfrageformular.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 12:11:03 +01:00

29 lines
1.1 KiB
TypeScript

import type { APIRoute } from "astro";
import { medusaConfig } from "../../../../lib/medusa";
export const prerender = false;
/**
* Dokument-Download fürs Firmenportal. Ein Link im Browser kann kein
* Bearer-Token mitschicken; deshalb holt diese Route die Datei mit dem
* Token aus dem Cookie und reicht sie durch.
*/
export const GET: APIRoute = async ({ params, cookies, redirect }) => {
const token = cookies.get("customer_jwt")?.value;
if (!token) return redirect(`/konto/anmelden?redirect=/konto/firma`);
const { url, key } = medusaConfig();
const res = await fetch(`${url}/store/customers/me/b2b/documents/${encodeURIComponent(params.id ?? "")}`, {
headers: { Authorization: `Bearer ${token}`, "x-publishable-api-key": key },
});
if (!res.ok) return new Response("Dokument nicht gefunden.", { status: res.status === 401 ? 401 : 404 });
return new Response(res.body, {
headers: {
"Content-Type": res.headers.get("Content-Type") ?? "application/octet-stream",
"Content-Disposition": res.headers.get("Content-Disposition") ?? "attachment",
"Cache-Control": "private, no-store",
},
});
};