forked from fahrPool/fahrPool
docs: add root setup README and fix stale auth.user_role() reference
There was no end-to-end runbook for getting from a fresh clone to a running dev environment -- the sequence was scattered across script comments and .env.example. Add a root README.md covering secrets generation, template rendering, docker compose up, migrations, first admin user creation, and the non-Docker web/ dev alternative, plus a heads-up that the admin@aushilfsfahrer.local test password was reset out-of-band during implementation and isn't recorded anywhere. Replace web/README.md's untouched create-next-app boilerplate (which mentioned yarn/pnpm/bun and "Deploy on Vercel") with a one-line pointer to the root README, since it was actively misleading for this self-hosted Docker project. Also fix the design spec still naming the helper auth.user_role() -- it was renamed to public.user_role() during Task 3 due to the auth-schema lockdown; the migrations and plan already reflect this.
This commit is contained in:
parent
d03052ca73
commit
bf7af326f4
|
|
@ -0,0 +1,119 @@
|
||||||
|
# Aushilfsfahrer
|
||||||
|
|
||||||
|
Selbst gehosteter Supabase-Stack (Docker Compose) + Next.js-Frontend
|
||||||
|
("Fundament: Auth & Rollen"). Diese Anleitung bringt eine frische Kopie des
|
||||||
|
Repos zum Laufen.
|
||||||
|
|
||||||
|
## Voraussetzungen
|
||||||
|
|
||||||
|
- Docker (mit Docker Compose)
|
||||||
|
- Node.js + npm
|
||||||
|
- `npx supabase` (Supabase CLI, wird beim ersten Aufruf automatisch via npx
|
||||||
|
geladen -- keine globale Installation noetig)
|
||||||
|
|
||||||
|
## 1. Secrets generieren
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node scripts/generate-secrets.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Gibt vier Zeilen aus: `POSTGRES_PASSWORD`, `JWT_SECRET`, `ANON_KEY`,
|
||||||
|
`SERVICE_ROLE_KEY`.
|
||||||
|
|
||||||
|
## 2. `.env` anlegen
|
||||||
|
|
||||||
|
Kopiere `.env.example` nach `.env` und trage die vier generierten Werte ein.
|
||||||
|
`ANON_KEY` zusaetzlich auch fuer `NEXT_PUBLIC_SUPABASE_ANON_KEY` eintragen
|
||||||
|
(gleicher Wert, zwei Variablen).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# .env editieren
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Config-Dateien aus Templates rendern
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node scripts/render-templates.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Rendert `volumes/api/kong.yml` und `volumes/db/init/99-roles.sql` aus ihren
|
||||||
|
`.template`-Vorlagen mit den echten Secrets aus `.env`. **Ohne diesen Schritt
|
||||||
|
crashloopen `auth`/`rest`/`storage`, bzw. Kong liefert 401 auf jede Route.**
|
||||||
|
Muss vor Schritt 4 laufen.
|
||||||
|
|
||||||
|
## 4. Stack starten
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
docker compose ps
|
||||||
|
```
|
||||||
|
|
||||||
|
Bringt den kompletten Stack hoch: Postgres, GoTrue (Auth), PostgREST,
|
||||||
|
Storage, Meta, Studio, Kong (API-Gateway) und den containerisierten `web`-
|
||||||
|
Service. Erwartet: alle Services `healthy` oder `running` (Kong/Studio haben
|
||||||
|
keinen Healthcheck definiert, sind aber `running`, sobald sie starten).
|
||||||
|
|
||||||
|
- API/Kong: `http://localhost:8000` (Port aus `KONG_HTTP_PORT`)
|
||||||
|
- Studio: `http://127.0.0.1:8082` (Port aus `STUDIO_PORT`)
|
||||||
|
- Web-App: `http://localhost:3000`
|
||||||
|
|
||||||
|
## 5. Migrationen anwenden
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx supabase@latest db push --db-url "postgres://postgres:${POSTGRES_PASSWORD}@127.0.0.1:${POSTGRES_PORT}/${POSTGRES_DB}"
|
||||||
|
```
|
||||||
|
|
||||||
|
`${POSTGRES_PASSWORD}`, `${POSTGRES_PORT}`, `${POSTGRES_DB}` aus der `.env`
|
||||||
|
einsetzen (oder vorher als Shell-Variablen exportieren). Erwartet: Ausgabe
|
||||||
|
listet die Migrationen aus `supabase/migrations/` als angewendet.
|
||||||
|
|
||||||
|
## 6. Ersten Admin-Nutzer anlegen
|
||||||
|
|
||||||
|
Der `handle_new_user()`-Trigger legt jedes neue Profil bewusst immer mit
|
||||||
|
`role = readonly` an (Privilege-Escalation-Schutz -- die Rolle wird nie aus
|
||||||
|
Signup-Metadaten uebernommen, siehe `supabase/migrations/20260704092843_profiles.sql`).
|
||||||
|
Ein Admin muss die Rolle danach explizit setzen:
|
||||||
|
|
||||||
|
1. Studio oeffnen (`http://127.0.0.1:8082`) -> Authentication -> Add user ->
|
||||||
|
E-Mail/Passwort setzen (optional User Metadata `{ "name": "..." }`).
|
||||||
|
Alternativ per GoTrue-Admin-API (`POST /auth/v1/admin/users` ueber Kong,
|
||||||
|
mit `Authorization: Bearer <SERVICE_ROLE_KEY>`), z. B. via `curl`.
|
||||||
|
2. Rolle im SQL Editor (Studio) auf `admin` setzen:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
update public.profiles set role = 'admin' where name = 'Admin';
|
||||||
|
select name, role from public.profiles;
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. Lokale Entwicklung ohne Docker fuer `web/` (Alternative zu Schritt 4)
|
||||||
|
|
||||||
|
Der `web`-Service kann auch ausserhalb von Docker laufen, waehrend der
|
||||||
|
uebrige Stack (`db`, `auth`, `rest`, `storage`, `meta`, `studio`, `kong`) in
|
||||||
|
Docker Compose bleibt:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd web
|
||||||
|
cp .env.local.example .env.local
|
||||||
|
# .env.local editieren (NEXT_PUBLIC_SUPABASE_ANON_KEY = derselbe ANON_KEY wie in der Root-.env)
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
`web/.env.local.example` verwendet fuer `SUPABASE_INTERNAL_URL` denselben
|
||||||
|
extern erreichbaren Wert wie `NEXT_PUBLIC_SUPABASE_URL` (`http://localhost:8000`),
|
||||||
|
da es ohne Docker-Netzwerk keinen internen Hostnamen `kong` gibt. Im
|
||||||
|
Docker-Container zeigt dieselbe Variable stattdessen auf `http://kong:8000`.
|
||||||
|
|
||||||
|
## Hinweis: Admin-Testpasswort nicht bekannt
|
||||||
|
|
||||||
|
Das Passwort des waehrend der Implementierung angelegten Admin-Accounts
|
||||||
|
(`admin@aushilfsfahrer.local`) wurde in den Tasks 6/7/8/9 mehrfach
|
||||||
|
out-of-band ueber die GoTrue-Admin-API auf Testwerte zurueckgesetzt, um
|
||||||
|
Login-Flows zu verifizieren -- keiner dieser Testwerte wurde irgendwo
|
||||||
|
gespeichert. Wer sich mit diesem Account anmelden muss:
|
||||||
|
|
||||||
|
- Passwort erneut per GoTrue-Admin-API zuruecksetzen
|
||||||
|
(`PUT /auth/v1/admin/users/<user-id>` mit `{"password": "..."}`,
|
||||||
|
`Authorization: Bearer <SERVICE_ROLE_KEY>` aus der Root-`.env`), oder
|
||||||
|
- einen neuen Admin-Nutzer wie in Schritt 6 beschrieben anlegen.
|
||||||
|
|
@ -56,7 +56,7 @@ Policies in allen Folge-Teilprojekten.
|
||||||
`profiles`-Eintrag mit Standardrolle an, wenn ein Admin einen Nutzer
|
`profiles`-Eintrag mit Standardrolle an, wenn ein Admin einen Nutzer
|
||||||
anlegt
|
anlegt
|
||||||
- Row Level Security ist auf allen fachlichen Tabellen aktiv. Eine
|
- Row Level Security ist auf allen fachlichen Tabellen aktiv. Eine
|
||||||
`SECURITY DEFINER`-Funktion `auth.user_role()` liest die Rolle des
|
`SECURITY DEFINER`-Funktion `public.user_role()` liest die Rolle des
|
||||||
aktuell eingeloggten Nutzers und wird in den RLS-Policies referenziert
|
aktuell eingeloggten Nutzers und wird in den RLS-Policies referenziert
|
||||||
- Rechtematrix (aus `CLAUDE.md` abgeleitet, gilt als Vorgabe für künftige
|
- Rechtematrix (aus `CLAUDE.md` abgeleitet, gilt als Vorgabe für künftige
|
||||||
Teilprojekte):
|
Teilprojekte):
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,5 @@
|
||||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
# web
|
||||||
|
|
||||||
## Getting Started
|
See the root `README.md` for the full setup sequence — this is a
|
||||||
|
sub-directory of a larger self-hosted Supabase + Next.js project, not a
|
||||||
First, run the development server:
|
standalone `create-next-app`.
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
# or
|
|
||||||
yarn dev
|
|
||||||
# or
|
|
||||||
pnpm dev
|
|
||||||
# or
|
|
||||||
bun dev
|
|
||||||
```
|
|
||||||
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
||||||
|
|
||||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
|
||||||
|
|
||||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
To learn more about Next.js, take a look at the following resources:
|
|
||||||
|
|
||||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
||||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
||||||
|
|
||||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
|
||||||
|
|
||||||
## Deploy on Vercel
|
|
||||||
|
|
||||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
||||||
|
|
||||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue