fix(better-auth): array support#2617
Conversation
📝 WalkthroughWalkthroughThe PR refactors Better Auth adapter configuration to properly handle array field support. It introduces a new config module defining Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4957aa1 to
b5a1b44
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/auth-adapters/better-auth/test/adapter.test.ts (1)
41-51: Minor: mock$transactionrecursion creates a freshoauthClientmock per call.
$transactioncallsmakeDb(captured)again, so the inneroauthClient.createis a new function instance each time.capturedis shared by reference so test assertions still work, but if a future test relies on identity (e.g.,expect(spy).toHaveBeenCalled()on the outer mock), it'll silently miss the tx path. Not an issue for the current assertions — flagging only as a forward-looking note.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/auth-adapters/better-auth/test/adapter.test.ts` around lines 41 - 51, The mock created by makeDb recreates oauthClient for each $transaction because $transaction calls makeDb(captured) again; instead, build the db object once inside makeDb and have $transaction invoke cb(db) so the same oauthClient.create instance is used across transactions (refer to makeDb, $transaction, and oauthClient.create) to preserve identity for spies while still sharing the captured object.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/auth-adapters/better-auth/test/adapter.test.ts`:
- Around line 41-51: The mock created by makeDb recreates oauthClient for each
$transaction because $transaction calls makeDb(captured) again; instead, build
the db object once inside makeDb and have $transaction invoke cb(db) so the same
oauthClient.create instance is used across transactions (refer to makeDb,
$transaction, and oauthClient.create) to preserve identity for spies while still
sharing the captured object.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 982bdf4c-802c-47e1-9010-00cca1b01e3d
📒 Files selected for processing (4)
packages/auth-adapters/better-auth/src/adapter.tspackages/auth-adapters/better-auth/src/config.tspackages/auth-adapters/better-auth/src/schema-generator.tspackages/auth-adapters/better-auth/test/adapter.test.ts
Summary
Fixes #2615.
This updates the ZenStack Better Auth adapter so Better Auth array fields are preserved for PostgreSQL-backed ZenStack schemas instead of being JSON-stringified before ZenStack validation. The adapter config now exposes
supportsArrays, defaulting to native array support for PostgreSQL and disabled array support for SQLite.Schema generation now uses the same capability decision as runtime:
string[]andnumber[]become nativeString[]andInt[]when arrays are supported, and fall back toJsonfields when they are not.This problem prevents normal use of Better Auth OAuth Provider plugin.
Validation
pnpm --filter @zenstackhq/better-auth lintpnpm --filter @zenstackhq/better-auth buildpnpm --filter @zenstackhq/better-auth testSummary by CodeRabbit
Release Notes
Refactor
Tests