Skip to content

Commit cfaabbb

Browse files
Copilothotlong
andcommitted
fix: update README adapter example, add ROADMAP note and changeset
- README: Update ObjectQL adapter example to show correct factory-based DBAdapterInstance pattern instead of raw adapter object - ROADMAP: Add v3.x migration note documenting the bug fix - Changeset: Add patch changeset for @objectstack/plugin-auth Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 27db9f3 commit cfaabbb

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@objectstack/plugin-auth": patch
3+
---
4+
5+
fix: AuthPlugin error handling & database adapter config
6+
7+
- `AuthManager.handleRequest()` now inspects `response.status >= 500` and logs the error body via `console.error`, since better-auth catches internal errors and returns 500 Responses without throwing.
8+
- `AuthPlugin.registerAuthRoutes()` also logs 500+ responses via `ctx.logger.error` for structured plugin logging.
9+
- `createDatabaseConfig()` now wraps the ObjectQL adapter as a `DBAdapterInstance` factory function so better-auth's `getBaseAdapter()` correctly recognises it (via `typeof database === "function"` check) instead of falling through to the Kysely adapter path.

ROADMAP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ business/custom objects, aligning with industry best practices (e.g., ServiceNow
329329
**Migration (v3.x → v4.0):**
330330
- v3.x: The `SystemObjectName` constants now emit `sys_`-prefixed names. Implementations using `StorageNameMapping.resolveTableName()` can set `tableName` to preserve legacy physical table names during the transition.
331331
- v3.x: The `@objectstack/plugin-auth` ObjectQL adapter now includes `AUTH_MODEL_TO_PROTOCOL` mapping to translate better-auth's hardcoded model names (`user`, `session`, `account`, `verification`) to protocol names (`sys_user`, `sys_session`, `sys_account`, `sys_verification`). Custom adapters must adopt the same mapping.
332+
- v3.x: **Bug fix**`AuthManager.createDatabaseConfig()` now wraps the ObjectQL adapter as a `DBAdapterInstance` factory function (`(options) => DBAdapter`). Previously the raw adapter object was passed, which fell through to the Kysely adapter path and failed silently. `AuthManager.handleRequest()` and `AuthPlugin.registerAuthRoutes()` now inspect `response.status >= 500` and log the error body, since better-auth catches internal errors and returns 500 Responses without throwing.
332333
- v4.0: Legacy un-prefixed aliases will be fully removed.
333334

334335
---

packages/plugins/plugin-auth/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,22 @@ const adapter = createObjectQLAdapter(dataEngine);
232232
// Mapping: { user: 'sys_user', session: 'sys_session', account: 'sys_account', verification: 'sys_verification' }
233233
console.log(AUTH_MODEL_TO_PROTOCOL);
234234

235-
// Better-auth uses this adapter for all database operations
235+
// better-auth requires a DBAdapterInstance (factory function), not a raw adapter object.
236+
// Passing a plain object falls through to the Kysely adapter path and fails silently.
237+
// Wrap the adapter in a factory function:
236238
const auth = betterAuth({
237-
database: adapter,
239+
database: (options) => ({
240+
id: 'objectql',
241+
...adapter,
242+
transaction: async (cb) => cb(adapter),
243+
}),
238244
// ... other config
239245
});
240246
```
241247

248+
> **Note:** `AuthManager` handles this wrapping automatically when you provide a `dataEngine`.
249+
> You only need the factory pattern above when using `createObjectQLAdapter()` directly.
250+
242251
## Development
243252

244253
```bash

0 commit comments

Comments
 (0)