Add database integration, auth API, admin/user portals, and deploy-db.sh

This commit is contained in:
2026-06-27 16:40:58 -05:00
parent 26559d4cf8
commit cc59177a74
25 changed files with 1423 additions and 118 deletions
+47 -6
View File
@@ -21,23 +21,64 @@ next.config.js
tsconfig.json
src/app/layout.tsx
src/app/page.tsx
src/app/login/page.tsx
src/app/admin/page.tsx
src/app/user/page.tsx
src/app/api/...
src/components/Navbar.tsx
src/components/MeasuredText.tsx
src/lib/db.ts
src/lib/schema.ts
src/lib/auth.ts
deploy-db.sh
README.md
```
## Database
The app connects to a PostgreSQL database using the `DATABASE_URL` environment variable.
### Deploy / rotate the database secret on Kubernetes
Run the helper script. It generates a secure random password, encrypts it to `~/.lahuasca-db-pass.enc`, and applies it to the `la-huasca-db-secrets` secret in the `la-huasca` namespace.
```bash
./deploy-db.sh
```
To reveal the stored password, use the PIN `78963`:
```bash
./deploy-db.sh reveal
```
### Initialize the database schema and seed data
Once the database is reachable and `DATABASE_URL` is set, start the dev server and call:
```bash
curl -X POST http://localhost:3000/api/db/init
```
To reset everything (drops and recreates tables with seed data):
```bash
curl -X POST "http://localhost:3000/api/db/init?reset=true"
```
## Authentication
The app now includes simple browser-local authentication with two hardcoded accounts:
The app includes JWT-based session authentication backed by the database. Demo accounts are seeded automatically:
- `admin` / `admin` Admin portal (`/admin`)
- `user` / `user` User portal (`/user`)
- `admin` / `admin` Admin portal (`/admin`)
- `user` / `user` User portal (`/user`)
The logged-in role is stored in `localStorage`. The **Login / Logout** control lives in the Navbar.
The **Login / Logout** control lives in the Navbar.
## Admin portal
Visit `/admin` after logging in as `admin` to upload images. Images are previewed in a gallery and can be deleted individually. For now, uploaded images are stored as base64 strings in the browser's `localStorage` under the key `la-huasca-admin-images` — they are not persisted on a server.
Visit `/admin` after logging in as `admin` to upload images. Images are previewed in a gallery and can be deleted individually. Uploaded images are now persisted in PostgreSQL.
## User portal
Visit `/user` after logging in as `user` to see a member portal with mock reservations, discount coupons, offers, the WiFi password, and a list of benefits.
Visit `/user` after logging in as `user` to see a member portal with reservations, discount coupons, offers, the WiFi password, and a list of benefits.