Skip to content

[Enhancement] Use better-auth modelName and fields mapping for ObjectQL adapter (snake_case compatibility) #896

Description

@hotlong

Context

Currently, the ObjectQL adapter for better-auth passes field names as-is from better-auth's camelCase queries to ObjectStack's snake_case database schema. This causes query failures (e.g., login, account lookup) when field names don't match (see Bug #893).

Proposal

Implement Approach B: declare model/field mapping in the better-auth configuration using its official modelName and fields options for each core auth model.
需要考虑所有插件用到的表,包括org等

Details

Instead of runtime camelCase ↔ snake_case conversion in the adapter, leverage better-auth's documented schema customization:

exportconstauth=betterAuth({user: {modelName: "sys_user",fields: {emailVerified: "email_verified",createdAt: "created_at",updatedAt: "updated_at",},},session: {modelName: "sys_session",fields: {userId: "user_id",expiresAt: "expires_at",ipAddress: "ip_address",userAgent: "user_agent",createdAt: "created_at",updatedAt: "updated_at",},},account: {modelName: "sys_account",fields: {userId: "user_id",providerId: "provider_id",accountId: "account_id",accessToken: "access_token",refreshToken: "refresh_token",idToken: "id_token",accessTokenExpiresAt: "access_token_expires_at",refreshTokenExpiresAt: "refresh_token_expires_at",createdAt: "created_at",updatedAt: "updated_at",},},verification: {modelName: "sys_verification",fields: {expiresAt: "expires_at",createdAt: "created_at",updatedAt: "updated_at",},},});

This ensures better-auth always uses the correct field names for data persistence and querying via ObjectQL.

Benefits

  • Single-point schema mapping, no runtime conversion
  • Cleaner adapter logic
  • Official/documented API usage
  • Reduces risk of edge-case bugs

Tasks

  • Add modelName and fields for all core models in better-auth config
  • Update auth-manager.ts to construct config accordingly
  • Review/adjust adapter and tests as needed
  • Validate sign-in, sign-up, and all account workflows
  • Document the mapping approach in README

相关问题: #893

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions