Replace demo auth with better-auth#52
Merged
Merged
Conversation
session auth and add production deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
demoAuthmiddleware with realcookie-based session auth using better-auth (Prisma
adapter, email/password provider). All protected
routes return
401without a valid session;cross-patient access returns
403.infra/deploy.shhandles build → migrate → seed →systemd restart → health poll in one command. Runbook
updated with the restore evidence gate as a
mandatory pre-start step.
What changed
Backend
better-authmounted at/api/auth/*;Session,Account,Verificationmodels added via migrationsessionAuth.tsreplacesdemoAuth.ts:requireAuth+requirePatientAccess+ per-routeIDOR ownership checks on all ID-based endpoints
(not just the first) to prevent cross-tenant writes
(multipart body now available); file cleanup on all
non-success exits
auth.api.signUpEmailforcorrect scrypt hashing; stable hardcoded IDs for
idempotent upserts; Account backfill for pre-auth
users
Frontend
AuthProvider+useAuth()hook;ProtectedRoute;LoginPagewithfetchOptions.onSuccessredirect (race-free,library-idiomatic)
user.patientId;AppLayoutlogout buttonInfra
infra/deploy.sh: build order fixed (fullnpm cibefore
tsc/prisma), migration hard-fails onerror, restore evidence gate, 30s health poll
infra/systemd/havenhold-api.service:After=postgresql.service,EnvironmentFilefrom.envdeploy.shvalidatesVITE_AUTH_BASE_URLandVITE_API_BASE_URLare present and non-empty beforefrontend build
Security fixes included
requirePatientAccesstightened: missing/emptypatientId now returns
403(previously bypassed viafalsy short-circuit)
not just the first
parses multipart body
Frontend
AuthProvider+useAuth()hook;ProtectedRoute;LoginPagewithfetchOptions.onSuccessredirect (race-free, library-idiomatic)user.patientId;AppLayoutlogout buttonInfra
infra/deploy.sh: build order fixed (fullnpm cibeforetsc/prisma), migrationhard-fails on error, restore evidence gate, 30s health poll
infra/systemd/havenhold-api.service:After=postgresql.service,EnvironmentFilefrom.envdeploy.shvalidatesVITE_AUTH_BASE_URLandVITE_API_BASE_URLare present andnon-empty before frontend build
Security fixes included
requirePatientAccesstightened: missing/empty patientId now returns403(previouslybypassed via falsy short-circuit)
Test plan
npm run lint— 0 errorscd server && npm run build— 0 errors/api/feed/:idreturns401/login403curlsmoke tests from runbook verification section