-
-
Notifications
You must be signed in to change notification settings - Fork 199
Conversation
lane711
commented
Apr 1, 2026
Hey @ivoilic — thanks for putting this together. Replacing the built-in auth with Better Auth is a solid architectural direction, and we appreciate the effort here. Removing ~6K lines of custom auth code in favor of a well-maintained library with OAuth providers, session management, and 2FA out of the box is exactly the kind of modernization SonicJS needs.
We've reviewed the PR and here's our assessment:
What we like:
- Clean separation of concerns — Better Auth handles auth, SonicJS handles CMS
- Significant code reduction (~6,100 lines removed, ~1,600 added)
- OAuth provider support out of the box
- Well-structured integration approach
Current blockers:
- The PR is ~60 days stale and would need a rebase on latest main — we've made significant security changes since January (PBKDF2 hashing, CSRF protection, rate limiting, CORS, security headers, RBAC enforcement)
- Migration path for existing users with current password hashes needs to be defined
- E2E test coverage needed for the new auth flow
- This is a breaking change that would need a major version bump
Our plan:
We're likely going to move in this direction in the near term. We're currently finishing up a security hardening cycle (v2.8.3–v2.9.x), and once that's stable, Better Auth integration makes a lot of sense as the foundation for v3.0.
Would you be interested in rebasing this on latest main when we're ready to kick off that work? We'd love to collaborate on making this happen. 🙏
lane711
commented
Apr 1, 2026
After further discussion, we've decided to take a different approach — instead of replacing the built-in auth entirely, we're going to build OAuth/social login as a plugin on top of the existing (now hardened) auth system. See issue #737 for the full plan.
Your PR was genuinely helpful as inspiration for the provider abstraction patterns. We'll be referencing it as we build the OAuth plugin.
We're closing this PR, but want to sincerely thank you @ivoilic for the work and the push toward better auth in SonicJS. If you're interested in contributing to the OAuth providers plugin (#737), we'd love to have you involved! 🙏
lane711
commented
Apr 1, 2026
Research: Better Auth + Cloudflare Workers Compatibility
For future reference, here's what we found when evaluating Better Auth for SonicJS's Cloudflare Workers runtime:
🚨 Critical: createRequire crash (Issues #6665, #6690)
Better Auth fails to load in Cloudflare Workers — crashes at module initialization with a createRequire(import.meta.url) error. Reported Dec 2025, still unresolved. No reliable workaround exists. This alone is a showstopper for SonicJS.
⚠️ 33-second hangs + 503s
A developer documented 33-second request hangs, mysterious 503s, and session dropouts when running Better Auth on Workers + D1. Root cause: Better Auth's singleton instance lifecycle doesn't fit Workers' stateless model. Dual auth instances create SQLite WAL lock contention in D1. Required completely rethinking auth instance creation (one per request, not singleton).
⚠️ D1 adapter issues (Issues #3552, #4732, #7487)
- D1 adapter setup is problematic — multiple reports of it not working properly
- Transactions defaulting to
truein v1.3.10+ breaks D1 (D1 doesn't support nested transactions) - Kysely adapter requires specific undocumented wrapping
⚠️ Third-party wrapper required
The community had to create a separate better-auth-cloudflare package to make integration workable. Hono's own docs only recently added a CF Workers example.
Our decision
We're keeping SonicJS's built-in auth (hardened in v2.8.3–v2.9.x) and building OAuth/social login as a plugin instead (#737). The built-in auth is purpose-built for Cloudflare Workers + D1 and doesn't have these compatibility issues.
If Better Auth resolves these CF Workers issues in the future, we can revisit.
lane711
commented
May 29, 2026
Reopening: upstream blockers resolved, tentative v3 directionReopening this PR with updated context. @ivoilic — apologies for the long delay. Since this PR was closed on April 1, we've taken another look at the Better Auth + Cloudflare Workers landscape, and the picture has materially changed. The blockers cited at close time were actually already fixed when we wrote that comment. Upstream blocker status (re-checked)
In short: all four cited showstoppers were closed months before we cited them. That's on us — the closing comment should have held up better against re-verification. Currently open Workers-adjacent issues
No open Workers- or D1-blocking issues beyond these. The Better Auth itself is on v1.6.11 (May 12, 2026) with v1.7 in beta — shipping roughly weekly. Why we're reconsidering: BetterAuth vs current SonicJS authIssues like #803 (custom profile fields stripped from Feature matrixCore auth
Social / Enterprise SSO
MFA
Authorization / RBAC
Multi-tenancy
API & tokens
Admin
DX
Compliance
Tentative plan: target v3.0We're going to tentatively plan a Better Auth migration as part of v3.0. The reasoning:
Open questions we'll work through before merging:
@ivoilic — would love your collaborationYour original PR remains the right architectural direction. If you have bandwidth and interest in picking this back up against current Marking this as a v3 milestone target. Will leave the PR open while we scope and align. |
Uh oh!
There was an error while loading. Please reload this page.
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