Petvity moves from Auth.js to @bitbaum/accountkit one reversible step at a
time, as evig and kivvi do. Nothing changes while AUTH_RUNTIME is unset.
- Migration 0008: AccountKit's tables under an `auth_` prefix, plus the
users <-> auth_users mirror functions, inert until attached.
- scripts/db/accountkit-import.sql: accounts under their own ids, bcrypt
hashes byte for byte, verification kept, orangecat_sub as an `orangecat`
account row; refuses collisions, drift or a live shared runtime, then
attaches the triggers. The rehearsal CLI always rolls back.
- lib/auth/shared/: the runtime (ids: 'uuid', legacy bcrypt, AccountKit
0.16.0), a session reader re-read from `users` on every request, a bridge
that answers next-auth/react including "Sign in with OrangeCat", and a
Petvity row for a person AccountKit creates itself. AccountKit's own
credential endpoints stay closed; Petvity's writers stay the only ones.
- lib/auth/claims.ts: the ADMIN_EMAILS promotion rule, written once.
- The proxy has one routing function and two session sources.
- browser-smoke.yml runs the account journey once per runtime; the
AccountKit leg first runs the rehearsal and the real-database journeys.
docs/ACCOUNTKIT-MIGRATION.md records what is left before switching.
Claude-Session: https://claude.ai/code/session_019MDtmud6zcK4rStBGmYSML
Co-authored-by: Claude <noreply@anthropic.com>
* fix(auth): the proxy no longer re-issues the session cookie
Auth.js's auth() proxy wrapper appends a fresh session cookie to every
response it handles, Link prefetches included. A prefetch that left the
browser before Sign out came back after it and set the old, still-valid
JWT again, so the person stayed signed in. The new browser journey hit
this in about one sign-out in three.
The proxy now drops only the session-token Set-Cookie it would add; the
session still rolls through /api/auth/*, which SessionProvider calls on
every page load.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* ci(browser-smoke): register, sign out, sign in and no stray Google button
browser-smoke.yml runs scripts/ci/account-journey.mjs in Chromium against
the production build and a throwaway Postgres 17: register through
/register, see the portal, sign out from the sidebar, a wrong password
refused, the right one accepted, no sideways scroll on /login and
/register at 390px. With no GOOGLE_* pair it checks that no Google
provider is mounted and no Google button is drawn, the guard for the
invalid_client sign-in of 2026-10-30.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
---------
Co-authored-by: Claude <noreply@anthropic.com>
Google was always mounted, so with no GOOGLE_CLIENT_ID on the box a request
to it reached Google as client_id=undefined and failed with invalid_client.
No button shows it, but a provider that cannot sign anyone in should not be
mounted at all. It now mounts only with both keys, like OrangeCat beside it.
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
Co-authored-by: Claude <noreply@anthropic.com>
Forgot/reset pages render PasswordRecoveryForm from @bitbaum/accountkit 0.8.1
through a small adapter over Petvity's own routes, so users, bcrypt passwords,
roles and Auth.js sessions are untouched. The hand-written pages could stay
stuck after a network error; the shared form leaves its busy state and says so.
The reset route now answers an invalid link with code INVALID_TOKEN.
lib/auth/orangecat.ts (provider, profile without email, placeholder email,
the sub-keyed adapter wrapper) moves to @bitbaum/accountkit/orangecat v0.2.1,
which took it as one of its sources; its tests went with it. The
ADMIN_EMAILS guard is accountkit's emailEarnsPromotion.
Fixes a gap: forgot-password emailed a reset link to an account OrangeCat
had created. That address came from OrangeCat unverified, so the link would
have given whoever owns it a password on the OrangeCat person's account.
It now gets the same generic answer (mayReceivePasswordReset); a person
with a password of their own can still reset it. Two route tests.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
"Sign in with OrangeCat" (OIDC) is now the primary action on /login and
/register; email + password stays behind a disclosure so existing accounts
are not locked out. OrangeCat's own page carries Google, GitHub, email and
open registration.
- Provider: client_secret_post + PKCE + state, scope "openid profile email",
issuer https://orangecat.ch (ORANGECAT_OAUTH_ISSUER overrides). Absent,
not broken, until ORANGECAT_OAUTH_CLIENT_ID/SECRET are set.
- Users are keyed ONLY on the new users.orangecat_sub (additive migration
0007). The provider profile carries no email, so Auth.js never looks a
user up by email; a new sub always creates a new user. A taken email gets
an undeliverable @users.invalid placeholder.
- An OrangeCat login never earns ADMIN_EMAILS promotion (email unverified).
- Identity only: no OrangeCat token refresh, tokens not stored.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore: add a formatter, matching the style this repo already writes
singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.
Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* style: format with prettier (252 files)
Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* chore: teach git blame to skip the reformat
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Found while inventorying what repeats across the fleet. Cron auth appears in 43
files across 9 repos, and the copies have diverged into two behaviours:
petvity if (auth !== `Bearer ${process.env.CRON_SECRET}`) OPEN
evig if (authHeader !== `Bearer ${cronSecret}`) OPEN
kivvi if (!cronSecret) { ... } guarded
aoz-housing if (!cronSecret || authHeader !== `Bearer ${cronSecret}`) guarded
With CRON_SECRET unset, the template literal evaluates to the string
"Bearer undefined", so a request carrying exactly that header is authorised.
All 8 cron routes here had the open version.
Behind that gate: /api/cron/reset-demo wipes and reseeds the demo account, and
weekly-digest, health-alerts, vaccination-reminders, medication-reminders and
booking-reminders each email every opted-in owner. So the blast radius of a
missing environment variable was a stranger mass-mailing the userbase and
destroying demo data.
Not exploitable today — CRON_SECRET is set in production. It is a gate that
fails open on an absent secret, which is a normal thing to happen on a new
environment or a typo, and the failure is silent.
requireCronAuth() denies everything when the secret is absent or blank, logs why
so a broken deployment is loud rather than quiet, requires the Bearer scheme,
and compares with timingSafeEqual. The timing part is close to unexploitable
over TLS and is not the point; a helper that is obviously correct removes the
need for anyone to reason about whether it matters.
Two test files, and the second is the one that matters. cron.test.ts pins the
helper's behaviour, including that "Bearer undefined" is refused when
unconfigured. cron-routes.test.ts asserts against the directory that every cron
route calls requireCronAuth and no route mentions process.env.CRON_SECRET —
because fixing eight routes fixes eight routes, while checking the directory
fixes the ninth one nobody has written yet.
Also adds docs/repeatable-across-projects.md: the full measured inventory of
what repeats across 25 repos, and a first-principles rule for what to do with
each. The short version is that copy count is the wrong question — it measures
typing, which is free. The right question is what divergence costs, which sorts
duplication into four classes with four different correct answers, of which
"leave it alone" is one.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Groomer joins vet and sitter everywhere a professional exists:
- user_role enum + groomer_profiles (salon, services, from-price) + migration
- /api/groomers browse + /api/groomers/me CRUD; role plumbed through
registration (?role=groomer), become-a-pro, availability, bookings,
conflict guard, admin verification, dashboards, sidebar
- Find a Pro gains a Groomers tab; booking modal books grooming as a
one-hour session with the salon's from-price in the header
- Public pro profile renders groomers (salon, services, starting price)
- Resident groomer Nadia Roth / Salon Pfotenschick seeds via the daily
cron with a completed booking + 5-star review, so the tab ships alive
- 6 grooming services in the professionals SSOT; role badge tokens in
globals.css; ~25 strings x 9 locales
Verified end-to-end locally: register groomer -> profile -> visible in
browse -> booked 201 -> overlap 409. verify + build green.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
* chore: nudge CI (pull_request event was never delivered)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(ux): humane booking flow, self-serve pro upgrade, role-aware dashboard
Booking modal rebuilt around how people actually book:
- Sitter: drop-off/pick-up dates (no datetime-local minute-picking), live
'N nights × rate = total' before any commitment
- Vet: one date + tap-a-time-slot chips (1h appointments)
- Availability surfaced BEFORE submit: busy ranges fetched from the new
/api/bookings/busy (privacy-safe date ranges), clashing dates disable the
button with a plain-words warning instead of a post-submit 409
- One pet -> stated, not asked; request-not-final explainer under the CTA
True multi-tenancy path: existing owners can now become professionals —
/portal/become-a-pro (sidebar 'Offer your services') POSTs the new
/api/account/role (pet_owner -> vet/sitter only, trust-first like
registration), session refreshes in place via the update trigger.
Dashboard attention strip now spans every role: pending booking requests
(pros) and open orders (sellers) join adoption applications and vaccines.
24 new strings x 9 locales. verify green (1212 tests), build green,
modal + clash state + sidebar verified in the browser.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
* feat(bookings,shop): calendar conflict blocking + Stripe payment integration
Tier-1 scheduling: the booking API now rejects (409) any request that
overlaps a professional's active bookings or their self-declared blocked
dates; vets/sitters manage blocked ranges at /portal/professional-profile
(new professional_blocked_dates table + /api/availability CRUD).
Payments: full Stripe Checkout flow, env-gated like Resend — without
STRIPE_SECRET_KEY nothing changes; with it, checkout redirects to Stripe,
the signed webhook (/api/payments/webhook) marks orders paid, and unpaid
orders stay payable from /portal/orders (Pay now + paid/awaiting badges).
orders gains paid_at + checkout_session_id.
Critical bug found by the smoke test: the login JWT callback wrote
resolveRole(email) back to the DB, silently DEMOTING every vet/sitter to
pet_owner at their next sign-in (residents were safe only because they
never log in). ADMIN_EMAILS now only promotes; professional roles survive.
Verified end-to-end locally: sitter registers → blocks dates → owner
booking overlap 409, blocked-dates 409, disjoint 201; checkout w/o keys
falls back to recorded orders. verify green (1209 tests incl. 12 new).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* chore: nudge CI (pull_request event was never delivered)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
- ownership.test.ts: remove stale @ts-expect-error that was unused
after type narrowing made the assertion unnecessary
- unsubscribe-token.test.ts: non-null assert makeUnsubscribeToken()
return value in tests where NEXTAUTH_SECRET is set in beforeEach,
so callers accept string instead of string | undefined
pnpm build now passes TypeScript check cleanly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backfill for three helpers used by every protected route or every
new-user flow — the kind of code where a silent regression cascades.
- lib/auth/guards.ts (8 tests): requireSession authed vs not, the
exact 401 body shape, requireRole for matching/non-matching/no
session including the load-bearing assertion that pet_owner asking
for "admin" gets blocked, requireAdmin parametric over every
non-admin role, and that all failure shapes return identical bodies
so client UIs can handle uniformly.
- lib/i18n/portal-locale.ts (5 tests): cookie value supported / unset
/ unknown / empty string, plus parametric coverage of every locale
in routing.locales (so a new locale added to routing won't silently
break portal cookie reads).
- lib/domain/email-queue.ts (4 tests): single batch insert (not 4
separate inserts), canonical templateKey order, scheduling delays
match WELCOME_SEQUENCE values within a slack window, payload +
userId propagated to every row.
Suite at 491 pass (+18). No behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Both /login and /register accepted any returnTo value that started
with "/" — but "//evil.com".startsWith("/") is true, and the browser
treats "//host" as protocol-relative and navigates externally. A
prepared link like /login?returnTo=//evil.com would have bounced the
user off the platform after a successful login.
- New lib/auth/safe-redirect.ts: same-origin-only validation with the
three known bypass shapes covered (//host, /\\host, http(s)://host),
plus rejection of javascript: and data: schemes for completeness.
- Login + register: rawReturnTo.startsWith("/") replaced with
safeReturnTo(value, fallback). Register also accepts "next" as
alias — same handling.
- 16 tests across the safe (parametric) and unsafe (parametric)
matrices, plus null/undefined handling. Each unsafe variant gets
the fallback.
Not currently exploited (the platform doesn't email login links
with returnTo params), but a real latent gap. Cheap to close now
before someone wires up that flow.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Yesterday's commit (00627fb) shipped a settings toggle for the
welcome series, but users had no way to discover it from the email
itself. Closing the loop with a tokenized unsubscribe URL — works
for logged-out recipients (the common case for marketing email).
- lib/auth/unsubscribe-token.ts: HMAC-SHA256 over userId, signed with
NEXTAUTH_SECRET. Constant-time verification, length-checked before
timingSafeEqual to avoid throws on shorter inputs. Returns undefined
(not throws) when secret is missing so test/dev environments don't
break — production has the secret because NextAuth requires it.
- lib/email/templates.ts: base() takes optional unsubscribeUrl;
rendered as a footer link only when supplied. The 4 welcome
templates accept it via the WelcomePayload type. Transactional
templates (vaccination/medication/health/order) intentionally have
no opt-out — they're necessary for the service.
- /api/cron/emails + POST /api/account: build the URL from user.id at
send time (not enqueue time, so existing queued items get the link
retroactively, and the token-rotation point stays in one helper).
- /unsubscribe page (app/unsubscribe/page.tsx): server component,
GET shows confirmation form, server action verifies+flips
digestOptOut+redirects with done=1 to render the success card.
Three states: invalid link, confirm, done.
- proxy.ts: new PUBLIC_BYPASS_PATHS list for /unsubscribe — bypasses
intl routing AND skips the AUTH_PATHS redirect-when-logged-in (so
the email link works whether the recipient is logged in or not).
- 9 token-helper tests cover sign/verify, tampering, wrong-length,
missing-secret, URL-encoding, determinism, and secret-rotation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Full Phase 1 scaffold:
- Next.js 16 + TypeScript strict + Tailwind 4 + Neon/Drizzle + NextAuth 5
- 9-language i18n (EN DE FR ES JA ZH KO TR AR) with RTL support for Arabic
- SSOT config: species (10 types), health metrics (7 KPIs), pet signal system
- DB schema: pets, healthMetrics (unique per pet+day), vaccinations, medications,
healthRecords, emailQueue
- Numeric storage: weight=grams, temperature=centidegrees (no float drift)
- computePetSignal() — pure domain function, 9 unit tests passing
- API routes: auth, account, pets CRUD, health metrics (upsert), records,
vaccinations, medications, public pet profiles (no auth)
- Cron: health-alerts, vaccination-reminders, email queue (all Bearer-protected)
- Portal UI: dashboard, pet list, add pet, health tracking, log page, vaccinations
- Public influencer pet profiles at /[locale]/pets/[handle]
- Email templates: welcome sequence, health alert, vaccination reminder
pnpm build ✓ pnpm test ✓ (9/9)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>