Shop: move commerce logic into PocketBase hooks; public app unprivileged
The public (internet-facing) app logged in as the PocketBase superuser and held the Stripe secret key, so any bug in it could become full control of the database. Baskets, slot holds, Stripe PaymentIntents, the webhook that creates orders, and the payment-result lookup now run in PocketBase JS hooks (pocketbase/pb_hooks/shop, routes under /api/shop/*, plus a cron that releases expired holds every minute). The public app's routes keep their URLs but only proxy to those routes and manage the basket cookie; it has no PocketBase or Stripe secret. Booking emails are still rendered and sent by the public app (same renderer as the admin preview) from order data the webhook hook returns; it records the outcome via a narrow endpoint guarded by INTERNAL_API_SECRET. Also: slot add and order creation are now transactional; shop listings load anonymously (already public via API rules); shop API errors always reach the browser as JSON; the superuser client and stripe package are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
1f929c68ca
commit
773fecc090
14 changed files with 914 additions and 507 deletions
10
.env.example
10
.env.example
|
|
@ -1,15 +1,17 @@
|
|||
# Secrets read by docker-compose.yml via ${VAR:-} substitution.
|
||||
# Copy to .env at the project root and fill in.
|
||||
|
||||
# Stripe
|
||||
# Stripe. The secret key and webhook secret go to PocketBase only (the shop
|
||||
# API in pocketbase/pb_hooks); the public app gets just the publishable key.
|
||||
STRIPE_SECRET_KEY=sk_test_...
|
||||
PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
|
||||
STRIPE_WEBHOOK_SECRET=whsec_...
|
||||
STRIPE_CURRENCY=eur
|
||||
|
||||
# PocketBase superuser credentials (used by server-side basket/checkout/webhook APIs)
|
||||
POCKETBASE_ADMIN_EMAIL=admin@example.com
|
||||
POCKETBASE_ADMIN_PASSWORD=changeme
|
||||
# Shared by PocketBase and the public app so the public app can record
|
||||
# booking-email status on orders (its only write). Generate a long random
|
||||
# value, e.g.: openssl rand -hex 32
|
||||
INTERNAL_API_SECRET=
|
||||
|
||||
# Booking emails via Brevo's SMTP relay (Brevo → SMTP & API → SMTP).
|
||||
# Leave SMTP_HOST empty in development: emails are then written to the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue