diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..0744987 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit", + "hooks": [ + { + "type": "command", + "command": "python -c \"import sys,json; d=json.load(sys.stdin); fp=d.get('tool_input',{}).get('file_path') or d.get('tool_response',{}).get('filePath'); print(fp or '')\" | { IFS= read -r f; f=\"${f%$'\r'}\"; case \"$f\" in *.ts|*.tsx) root=$(git rev-parse --show-toplevel 2>/dev/null); (cd \"$root/web\" && npx eslint --fix \"$f\") 2>/dev/null;; esac; } || true" + } + ] + } + ] + } +} diff --git a/.claude/skills/curl-server-action/SKILL.md b/.claude/skills/curl-server-action/SKILL.md new file mode 100644 index 0000000..6dcb581 --- /dev/null +++ b/.claude/skills/curl-server-action/SKILL.md @@ -0,0 +1,63 @@ +--- +name: curl-server-action +description: Technique for driving this project's Next.js Server Actions via curl, without a browser — for manual/live verification of forms and mutations. Use whenever you need to test a Server Action (login, form submit, a drag-triggered action) from the command line. +--- + +# Driving Next.js Server Actions with curl + +Next.js Server Actions (`"use server"` functions used as `
` or called directly) don't accept a plain `-d key=value` POST — the framework encodes the action reference into the request, and the encoding differs depending on whether the action is **bound** or **unbound**. + +## Step 1: find the action encoding in the rendered HTML + +```bash +curl -s http://localhost:/ -o page.html +``` + +**Unbound action** (``, no `.bind()`): look for a single hidden field: + +```bash +grep -o '\$ACTION_ID_[a-z0-9]*' page.html +``` + +This hash **changes on every dev-server restart/rebuild** — always re-read it fresh from the current page load, never reuse a previously-seen value. + +**Bound action** (`someFn.bind(null, arg1, arg2)`): look for a triple of fields instead: + +```bash +grep -o '\$ACTION_REF_[a-z0-9]*\|\$ACTION_[a-z0-9]*:[01]' page.html +``` + +- `$ACTION_REF_` — empty-valued field referencing the action +- `$ACTION_:0` — bound marker, value `"$@1"` +- `$ACTION_:1` — JSON array of the bound arguments, e.g. `["abholort"]` + +## Step 2: submit with the matching fields + +Unbound: + +```bash +HASH=$(curl -s http://localhost:/login | grep -o '\$ACTION_ID_[a-z0-9]*' | head -1) +curl -s -c cookies.txt -X POST http://localhost:/login \ + -F "${HASH}=" \ + -F 'email=admin@aushilfsfahrer.local' \ + -F 'password=Admin123!' \ + -L -o response.html -w "HTTP_STATUS:%{http_code} FINAL_URL:%{url_effective}\n" +``` + +Bound (three extra `-F` fields instead of one): + +```bash +curl -s -b cookies.txt -X POST http://localhost:/some-page \ + -F '$ACTION_REF_3=' \ + -F '$ACTION_3:0={"id":"...","bound":"$@1"}' \ + -F '$ACTION_3:1=["abholort"]' \ + -F 'other_form_field=value' \ + -L -o response.html -w "HTTP_STATUS:%{http_code} FINAL_URL:%{url_effective}\n" +``` + +Reuse the cookie jar (`-b cookies.txt -c cookies.txt`) across requests to stay authenticated. + +## Gotchas + +- If a page renders **multiple** Server Action forms at once (e.g. a page with both a logout button and a content form), a naive `grep | head -1` may grab the wrong action's ID. Narrow the grep with surrounding context (e.g. `grep -B2 -A2 'Submit-Button-Label'`) or inspect the embedded JSON payload in the HTML, which includes `"name":""` next to the matching action id — use that to confirm you've got the right one. +- A plain `.env.local` misconfiguration (pointing at the wrong Supabase stack — see the `supabase-local-dev` skill) will make login *appear* to fail with a generic error even though the curl technique itself is correct. Verify the target stack before assuming the encoding is wrong. diff --git a/.claude/skills/rebuild-master-stack/SKILL.md b/.claude/skills/rebuild-master-stack/SKILL.md new file mode 100644 index 0000000..0e457e7 --- /dev/null +++ b/.claude/skills/rebuild-master-stack/SKILL.md @@ -0,0 +1,52 @@ +--- +name: rebuild-master-stack +description: Rebuilds and restarts the docker-compose "web" service with the current master branch code, then verifies it's serving. Use only when the user explicitly asks to see their changes live in the master/production-like stack (e.g. after merging a feature branch). +disable-model-invocation: true +--- + +# Rebuild Master Stack + +Only run this when the user explicitly asks (e.g. "rebuild the container", "show me this live", "restart the stack"). Never trigger it proactively — it restarts a shared, potentially-in-use service. + +## Steps + +1. Confirm you're operating from the main repo checkout (not a worktree), on `master`, with the change you want to deploy already merged there. + +2. Rebuild the `web` image: + + ```bash + docker compose build web + ``` + + If this is the first rebuild after a task that added new npm dependencies (check `web/package.json` diff against the previous deployed state), the build step already runs `npm install` inside the Docker build — no separate action needed there. But if you're instead testing directly against a local `npm run dev` outside Docker, remember to run `npm install` in `web/` yourself first (new dependencies aren't picked up automatically). + +3. Restart just the `web` container with the new image: + + ```bash + docker compose up -d web + ``` + +4. Verify it's actually serving the new code, not a stale cached image: + + ```bash + sleep 3 + curl -s -o /dev/null -w "Status: %{http_code}\n" http://localhost:3000/login + docker exec aushilfsfahrer-web-1 sh -c "ls /app/.next/server/app/ 2>&1" + ``` + + Pick a route that's specific to whatever just shipped (e.g. a new page directory) so you're confirming the *new* build actually landed, not just that *some* build is running. + +5. If the merge included new Supabase migrations, apply them to the master stack's database too — it does **not** share a database with the local Supabase CLI dev stack (see the `supabase-local-dev` skill). Check which migrations are missing: + + ```bash + docker exec -i aushilfsfahrer-db-1 psql -U postgres -d postgres -c "select version from supabase_migrations.schema_migrations order by version;" + ``` + + Apply any missing migration files directly and record them: + + ```bash + docker exec -i aushilfsfahrer-db-1 psql -U postgres -d postgres -v ON_ERROR_STOP=1 < supabase/migrations/.sql + docker exec -i aushilfsfahrer-db-1 psql -U postgres -d postgres -c "insert into supabase_migrations.schema_migrations (version) values ('') on conflict (version) do nothing;" + ``` + +Report the admin login URL/credentials back to the user once verified (`admin@aushilfsfahrer.local` / `Admin123!`, or the current password — see the `supabase-local-dev` skill if it's been reset). diff --git a/.claude/skills/supabase-local-dev/SKILL.md b/.claude/skills/supabase-local-dev/SKILL.md new file mode 100644 index 0000000..f2e0efe --- /dev/null +++ b/.claude/skills/supabase-local-dev/SKILL.md @@ -0,0 +1,57 @@ +--- +name: supabase-local-dev +description: Reference for working with this project's self-hosted Supabase stack — CLI working directory, the two parallel stacks running on this machine, test admin credentials, and pgTAP fixture conventions. Use whenever running supabase CLI commands, writing/debugging pgTAP tests, or verifying RLS behavior live. +--- + +# Supabase Local Dev — Reference + +## Run CLI commands from the repo root, never from `web/` + +```bash +npx supabase status +npx supabase start +npx supabase db reset +npx supabase test db +``` + +All of these must run from the repository root (where `supabase/` lives), not from `web/`. Running them from `web/` fails silently or picks up the wrong project config. + +## Two parallel stacks — don't mix them + +This machine typically runs **two independent Supabase stacks at once**: + +1. **Local Supabase CLI dev stack** (`npx supabase start`) — containers named `supabase_*_fundament-auth-rollen`, API on `http://127.0.0.1:54321`, Postgres on port 54322. This is the stack all automated task/review verification in this project uses. +2. **Docker-Compose "master" stack** (`docker compose up -d`, defined in the repo's `docker-compose.yaml`) — containers named `aushilfsfahrer-*`, Kong gateway on `http://localhost:8000`, Postgres on port 5432. This is what the user runs to click through the live app. + +Both can be running simultaneously. `web/.env.local` (gitignored, per-worktree) determines which one a local `npm run dev` talks to — check its `NEXT_PUBLIC_SUPABASE_URL` before assuming which stack you're hitting. Get the CLI stack's current anon key and URL with `npx supabase status` (repo root) rather than hardcoding a previously-seen value — it can change between resets. + +## Test admin account + +`admin@aushilfsfahrer.local` / `Admin123!`, role `admin`, exists in the local CLI dev stack. Its password gets reset periodically during development (out-of-band, via the GoTrue admin API) and isn't reliably documented anywhere — if login fails, reset it yourself: + +```bash +curl -s -X PUT http://127.0.0.1:54321/auth/v1/admin/users/ \ + -H "apikey: " \ + -H "Authorization: Bearer " \ + -H "Content-Type: application/json" \ + -d '{"password":"Admin123!"}' +``` + +If the user doesn't exist at all, create it via `POST /auth/v1/admin/users` with `email_confirm: true`, then set its role in `public.profiles` via `docker exec -i supabase_db_fundament-auth-rollen psql -U postgres -d postgres`. + +## pgTAP fixture conventions + +Tests live in `supabase/tests/*.sql`. Standard pattern for simulating a specific user's RLS context: + +```sql +insert into auth.users (id, email) values ('', 'someone@test.local'); +-- a trigger auto-creates a matching public.profiles row with role='readonly' +update public.profiles set role = 'fahrer' where id = ''; + +set local role authenticated; +set local request.jwt.claims to '{"sub": "", "role": "authenticated"}'; +-- ... run assertions as this user ... +reset role; +``` + +Every test file wraps its whole body in `begin; ... rollback;` so fixtures never persist. Run the full suite with `npx supabase test db` (after `npx supabase db reset` to apply migrations fresh) — check the file for the current `select plan(N);` count before adding tests, and update it.