Node.js/Express-Server als Ersatz für Cloudflare Pages Functions + D1 (läuft auf eigenem Server statt Cloudflare)
Build & Deploy / deploy (push) Waiting to run
Build & Deploy / deploy (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/* =====================================================================
|
||||
routes/account.js — Kundenkonto-Selbstbedienung: me, logout, delete (DSGVO Art. 17),
|
||||
export (DSGVO Art. 15/20). 1:1 portiert aus functions/api/account/*.js.
|
||||
===================================================================== */
|
||||
|
||||
import { Router } from "express";
|
||||
import { getCustomer, clearCustomerCookie } from "../lib/customer-auth.js";
|
||||
import { db } from "../db.js";
|
||||
|
||||
export const accountRouter = Router();
|
||||
|
||||
accountRouter.get("/api/account/me", async (req, res) => {
|
||||
const customer = await getCustomer(req);
|
||||
if (!customer) return res.json({ ok: false });
|
||||
return res.json({
|
||||
ok: true,
|
||||
customer: { email: customer.email, name: customer.name, provider: customer.provider, seit: customer.created_at },
|
||||
});
|
||||
});
|
||||
|
||||
accountRouter.post("/api/account/logout", (req, res) => {
|
||||
clearCustomerCookie(res);
|
||||
return res.json({ ok: true });
|
||||
});
|
||||
|
||||
accountRouter.post("/api/account/delete", async (req, res) => {
|
||||
const customer = await getCustomer(req);
|
||||
if (!customer) return res.status(401).json({ ok: false, error: "Nicht angemeldet." });
|
||||
|
||||
try {
|
||||
db.prepare(`DELETE FROM customers WHERE id = ?`).run(customer.id);
|
||||
} catch {
|
||||
return res.status(500).json({ ok: false, error: "Konto konnte nicht gelöscht werden. Bitte versuche es erneut." });
|
||||
}
|
||||
|
||||
clearCustomerCookie(res);
|
||||
return res.json({ ok: true });
|
||||
});
|
||||
|
||||
accountRouter.get("/api/account/export", async (req, res) => {
|
||||
const customer = await getCustomer(req);
|
||||
if (!customer) return res.status(401).json({ ok: false, error: "Nicht angemeldet." });
|
||||
|
||||
const daten = {
|
||||
konto: { email: customer.email, name: customer.name, anmeldeart: customer.provider, erstelltAm: customer.created_at },
|
||||
hinweis:
|
||||
"Dies sind alle Daten, die Van's DIY & Bastelbedarf zu deinem Kundenkonto speichert. " +
|
||||
"Bereits aufgegebene Bestellungen werden getrennt davon aus gesetzlichen Aufbewahrungsgründen " +
|
||||
"weiter gespeichert (siehe Datenschutzerklärung, Abschnitt Bestellabwicklung).",
|
||||
};
|
||||
|
||||
res.setHeader("Content-Disposition", 'attachment; filename="meine-daten.json"');
|
||||
return res.status(200).json(daten);
|
||||
});
|
||||
Reference in New Issue
Block a user