* feat(auth): every way in on AccountKit's own screens
Botsmann signed people in against OrangeCat's GoTrue (auth.users). It now
runs on AccountKit (@bitbaum/accountkit 0.23) with AccountKit's own forms:
/auth/signin offers email and password, an emailed sign-in link, a
passkey, recovery through the mailed link and the second factor;
/auth/signup is sign-up; /account carries the account panel ("Sign-in and
security" in the account menu). "Continue with OrangeCat" and the shared
sign-in show when their clients are set, the link and recovery when mail
is. The GoTrue routes (/api/auth/signin, signup, forgot-password,
resend-verification, profile) and pages (callback, forgot-password,
reset-password, verify-email) and the cookie-session client are gone.
AccountKit's tables live in a host accounts database (drizzle/, loki
accounts-db.conf); the data stays in the botsmann supabase schema, which
every route already read with the service-role client. verifyUser now reads
AccountKit's session; /api/user/profile moves onto it too. New accounts get
uuid ids, and migration 013 drops the person columns' keys to auth.users,
which a new person's id is not in. Nothing is deleted. The profile editor
writes AccountKit's name and image.
Existing people keep their rows: scripts/db/accountkit-people.sql lists
everyone who owns rows with their OrangeCat actor id, and
scripts/db/accountkit-import.sql gives each an account under the same id,
linked to OrangeCat by that actor id, never by address (loki
accountkit-supabase.yml rehearses it rolled back, then imports).
Pages were served with public, max-age=3600 to every browser, account pages
included: after sign-out the browser showed its cached /account. /account
and /auth/* are now private, no-store. The account menu's trigger has a name.
tests/__tests__/accounts runs the ways in and the import on the committed
migration; browser-smoke.yml's account job rehearses the import and runs
the browser journey against the production build with AccountKit's real
mail caught by a sink.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* fix(auth): send a signed-out visitor to sign in with the router
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* ci(auth): the shared sign-in's button is matched by how it starts
AccountKit 0.24 names only the providers Morulia publishes, so the label
changes with Morulia.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* ci(auth): expect the shared sign-in only once Morulia publishes a provider
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* ci: run the checks on the journey change
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
---------
Co-authored-by: Claude <noreply@anthropic.com>
4.6 KiB
Botsmann's Database
Where it is
Self-hosted. There is no supabase.com project, no hosted dashboard, and no bill from Supabase. We run the open-source Supabase stack in Docker on the Hetzner box "bitbaum", the same box that serves the app.
| API URL | https://supabase.orangecat.ch (Caddy → Kong on 127.0.0.1:8000) |
| Database | supabase-db container, Postgres, no published port |
| Our schema | botsmann — not public |
| Studio | https://supabase.orangecat.ch/ — behind Kong's basic auth |
| Keys | /opt/botsmann/shared/.env on the box |
If you find a hosted-dashboard link anywhere in this repo, it is a
leftover from before the move and it is wrong. pnpm run check:selfhost fails
the build on new ones.
Why we are not in public
One database backs several apps. OrangeCat owns public and has ~136 tables
there. Our table names collide with theirs — conversations, documents,
waitlist — and our 001 defines update_updated_at(), a function name
public already holds and OrangeCat's triggers call.
So every app gets its own schema. Ours is botsmann, pinned in one place:
// lib/constants.ts
export const DB_SCHEMA = 'botsmann';
Every client in lib/supabase.ts passes db: { schema: DB_SCHEMA }. A client
that forgets it reads public, where our tables do not exist, and PostgREST
answers PGRST205 — Could not find the table 'public.consultations'. That looks
like a dead database but is really a missing five words of config. It is what
took the app down; tests/__tests__/lib/supabase-schema.test.ts now guards it.
How migrations are applied
Automatically, on deploy. You never paste SQL anywhere.
Pushing to main runs .github/workflows/deploy.yml, which calls loki's
selfhost-deploy.yml. That pipeline runs
scripts/hetzner/apply-schema.sh botsmann … supabase:botsmann before restarting
the app. It:
- applies only files in
supabase/migrations/not already recorded inbotsmann._deploy_schema_history, - runs the batch in one transaction — all or nothing,
- refuses any migration containing a destructive statement, aborting the deploy rather than silently dropping production data.
Current state: 11 migrations applied, 13 tables in the schema.
Adding one
- Add
supabase/migrations/<NNN>_what_it_does.sql(the next number after the highest one there). Keep it forward-only and non-destructive, or the deploy will refuse it. - Open a PR. Merging deploys it and applies it.
A genuinely destructive change is applied by hand, then recorded so the automation skips it:
ssh ubuntu@167.233.22.31 "docker exec supabase-db psql -U postgres -d postgres \
-c \"INSERT INTO botsmann._deploy_schema_history(tag) VALUES ('0NN_what_it_does')\""
Checking the database
pnpm run test:db # connects with our schema and reports every expected table
Straight from the box, when you need to see the schema itself:
ssh ubuntu@167.233.22.31 \
"docker exec supabase-db psql -U postgres -d postgres \
-c '\\dt botsmann.*'"
Storage and auth
Storage (supabase-storage) is a shared service on the box, not per-app.
Buckets are configured in Studio. Botsmann no longer uses the stack's auth
(GoTrue): accounts are @bitbaum/accountkit (lib/accounts), with their
tables in a host accounts database (DATABASE_URL, migrations in drizzle/;
loki accounts-db.conf). Every route reads the botsmann schema with the
service-role client and filters by the session's user id (lib/api-utils.ts).
People who signed in through GoTrue before keep their ids:
scripts/db/accountkit-import.sql (run by loki accountkit-supabase.yml)
gave each one an account under the same id, linked to OrangeCat by their
actor id, never by address; they sign in with "Continue with OrangeCat". Storage policies live on storage.objects, which is shared with
every other app on this stack — scope any policy you add to our bucket, and
prefer a bucket per app over a shared one.
Resources
- Supabase docs — the product docs are still the right reference; only the hosted dashboard does not apply to us.
- pgvector
- PostgreSQL Row Level Security
- loki:
scripts/hetzner/apply-schema.sh,docs/infrastructure/migration-strategy.md