Replaced built-in auth with Better Auth #620
Open
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.
Description
Replaces custom JWT auth with Better Auth. Rather than maintain auth on top of Sonicjs itself this outsources that work to Better Auth and allows end users to setup a larger number of secure auth methods. This is a first pass for consideration and certainly needs more work. Sign-in/sign-up at
/auth/sign-in/emailand/auth/sign-up/email. Session in HTTP-only cookie. OTP Login and Magic Link plugins removed but magic link/email OTP can no be added viaauth.extendBetterAuth. RBAC and registration gating kept via Better Auth hooks.Env:
BETTER_AUTH_SECRET,BETTER_AUTH_URLChanges
auth/config.ts(Better Auth + Drizzle, hooks). App mounts handler at/auth/*, session middleware setsc.set('user'). Auth middleware drops JWT/KV.requireAuth/requireRoleuse session. Login/register forms POST to Better Auth. Migrations 032 (Better Auth tables,users.name), 033 (drop otp/magic_link tables).Testing
npm testpasses (40 files, 1174 tests)npm run e2eornpm run e2e:smoke— run locally to confirmChecklist