Skip to content

Commit 0cca954

Browse files
Copilothotlong
andcommitted
docs: update README, authentication guide, and ROADMAP for sys_ prefix adaptation
- Update plugin-auth README.md with sys_ prefixed object names and adapter mapping docs - Update authentication.mdx guide with protocol name mapping explanation - Update ROADMAP.md migration notes for better-auth adapter Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 4c6d7b2 commit 0cca954

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

ROADMAP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ business/custom objects, aligning with industry best practices (e.g., ServiceNow
162162

163163
**Migration (v3.x → v4.0):**
164164
- 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.
165+
- 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.
165166
- v4.0: Legacy un-prefixed aliases will be fully removed.
166167

167168
---
@@ -364,7 +365,7 @@ business/custom objects, aligning with industry best practices (e.g., ServiceNow
364365
- [ ] **Phase A: Core Driver** (v3.1) — `IDataDriver` + `ISchemaDriver` implementation, QueryAST→SQL compiler, plugin wrapper
365366
- [ ] **Phase B: Edge & Sync** (v3.2) — Embedded replica sync, WASM build for Cloudflare/Deno, offline write queue
366367
- [ ] **Phase C: Multi-Tenancy** (v3.3) — Database-per-tenant router, Turso Platform API integration
367-
- [ ] **Phase D: Advanced** (v4.0) — Vector search + `IAIService`, FTS5 + `ISearchService`, better-auth adapter
368+
- [ ] **Phase D: Advanced** (v4.0) — Vector search + `IAIService`, FTS5 + `ISearchService`, ~~better-auth adapter~~ (✅ done in plugin-auth)
368369
- [ ] Driver benchmark suite comparing performance across all drivers
369370

370371
### 6.2 Multi-Tenancy

content/docs/guides/authentication.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ That's it! Your authentication endpoints are now available at `/api/v1/auth/*`.
111111

112112
The plugin automatically uses ObjectQL for data persistence. No additional database configuration is required - it works with your existing ObjectQL setup.
113113

114-
The plugin creates the following auth objects:
115-
- `user` - User accounts
116-
- `session` - Active sessions
117-
- `account` - OAuth provider accounts
118-
- `verification` - Email/phone verification tokens
114+
The plugin creates the following auth objects (using ObjectStack `sys_` protocol names):
115+
- `sys_user` - User accounts (mapped from better-auth's `user` model)
116+
- `sys_session` - Active sessions (mapped from better-auth's `session` model)
117+
- `sys_account` - OAuth provider accounts (mapped from better-auth's `account` model)
118+
- `sys_verification` - Email/phone verification tokens (mapped from better-auth's `verification` model)
119+
120+
> **Note:** better-auth uses hardcoded model names (`user`, `session`, etc.). The ObjectQL adapter
121+
> automatically maps these to `sys_`-prefixed protocol names via `AUTH_MODEL_TO_PROTOCOL`.
122+
> Client-side API routes (`/api/v1/auth/*`) are **not affected** — they do not expose object names.
119123
120124
---
121125

@@ -569,12 +573,16 @@ try {
569573

570574
### ObjectStack Field Naming
571575

572-
The plugin uses ObjectStack's snake_case naming convention for field names, which is required by the ObjectStack protocol:
576+
The plugin uses ObjectStack's `sys_` prefix convention for protocol object names and snake_case for field names, which is required by the ObjectStack protocol:
573577

574-
- Table names: `user`, `session`, `account`, `verification` (compatible with better-auth)
578+
- Object names: `sys_user`, `sys_session`, `sys_account`, `sys_verification` (protocol names)
575579
- Field names: `email_verified`, `created_at`, `user_id` (snake_case)
576580

577-
The ObjectQL adapter automatically handles field name transformation between better-auth's expectations and ObjectStack's snake_case convention, providing seamless integration while maintaining protocol compliance.
581+
better-auth internally uses model names like `user` and `session`. The ObjectQL adapter (`AUTH_MODEL_TO_PROTOCOL` mapping) automatically translates these to `sys_`-prefixed protocol names, providing seamless integration.
582+
583+
> **Upgrade note:** If you have custom adapters or plugins that reference auth objects by name,
584+
> update them to use `sys_user`, `sys_session`, `sys_account`, `sys_verification`
585+
> (or import from `SystemObjectName` constants).
578586
579587
---
580588

packages/plugins/plugin-auth/README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ Authentication & Identity Plugin for ObjectStack.
3434
-**No Third-Party ORM** - No dependency on drizzle-orm or other ORMs
3535
-**Better-Auth Native Schema** - Uses better-auth's naming conventions for seamless migration
3636
-**Object Definitions** - Auth objects defined using ObjectStack's Object Protocol
37-
- `user` - User accounts (better-auth native table name)
38-
- `session` - Active sessions (better-auth native table name)
39-
- `account` - OAuth provider accounts (better-auth native table name)
40-
- `verification` - Email/phone verification tokens (better-auth native table name)
37+
- `sys_user` - User accounts (protocol name, mapped from better-auth's `user`)
38+
- `sys_session` - Active sessions (protocol name, mapped from better-auth's `session`)
39+
- `sys_account` - OAuth provider accounts (protocol name, mapped from better-auth's `account`)
40+
- `sys_verification` - Email/phone verification tokens (protocol name, mapped from better-auth's `verification`)
4141
-**ObjectQL Adapter** - Custom adapter bridges better-auth to ObjectQL
4242

4343
The plugin uses [better-auth](https://www.better-auth.com/) for robust, production-ready authentication functionality. All requests are forwarded directly to better-auth's universal handler, ensuring full compatibility with all better-auth features. Data persistence is handled by ObjectQL using **ObjectStack's snake_case naming conventions** for field names to maintain consistency across the platform.
@@ -187,7 +187,7 @@ The plugin uses **ObjectQL** for data persistence instead of third-party ORMs:
187187
```typescript
188188
// Object definitions use ObjectStack's snake_case naming conventions
189189
export const AuthUser = ObjectSchema.create({
190-
name: 'user', // better-auth compatible table name
190+
name: 'sys_user', // ObjectStack protocol name (better-auth model 'user' is mapped automatically)
191191
fields: {
192192
id: Field.text({ label: 'User ID', required: true }),
193193
email: Field.email({ label: 'Email', required: true }),
@@ -213,19 +213,25 @@ export const AuthUser = ObjectSchema.create({
213213
-**Compatible Schema** - Uses better-auth compatible table structure with ObjectStack's snake_case field naming
214214

215215
**Database Objects:**
216-
Uses better-auth compatible table names with ObjectStack's snake_case field naming:
217-
- `user` - User accounts (id, email, name, email_verified, created_at, etc.)
218-
- `session` - Active sessions (id, token, user_id, expires_at, ip_address, etc.)
219-
- `account` - OAuth provider accounts (id, provider_id, account_id, user_id, tokens, etc.)
220-
- `verification` - Verification tokens (id, value, identifier, expires_at, etc.)
216+
Uses ObjectStack `sys_` prefixed protocol names with snake_case field naming.
217+
The adapter automatically maps better-auth model names to protocol names:
218+
- `sys_user` (← better-auth `user`) - User accounts (id, email, name, email_verified, created_at, etc.)
219+
- `sys_session` (← better-auth `session`) - Active sessions (id, token, user_id, expires_at, ip_address, etc.)
220+
- `sys_account` (← better-auth `account`) - OAuth provider accounts (id, provider_id, account_id, user_id, tokens, etc.)
221+
- `sys_verification` (← better-auth `verification`) - Verification tokens (id, value, identifier, expires_at, etc.)
221222

222223
**Adapter:**
223-
The `createObjectQLAdapter()` function bridges better-auth's database interface to ObjectQL's IDataEngine with field name transformation:
224+
The `createObjectQLAdapter()` function bridges better-auth's database interface to ObjectQL's IDataEngine. It includes a model→protocol name mapping (`AUTH_MODEL_TO_PROTOCOL`) that translates better-auth's hardcoded model names (e.g. `user`) to ObjectStack protocol names (e.g. `sys_user`):
224225

225226
```typescript
226-
// Better-auth → ObjectQL Adapter (handles snake_case transformation)
227+
// Better-auth → ObjectQL Adapter (handles model name mapping + field transformation)
228+
import { createObjectQLAdapter, AUTH_MODEL_TO_PROTOCOL } from '@objectstack/plugin-auth';
229+
227230
const adapter = createObjectQLAdapter(dataEngine);
228231

232+
// Mapping: { user: 'sys_user', session: 'sys_session', account: 'sys_account', verification: 'sys_verification' }
233+
console.log(AUTH_MODEL_TO_PROTOCOL);
234+
229235
// Better-auth uses this adapter for all database operations
230236
const auth = betterAuth({
231237
database: adapter,

0 commit comments

Comments
 (0)