Skip to content

Commit 3dd6ea5

Browse files
Copilothotlong
andcommitted
Extract better-auth field mapping defaults into constants for maintainability
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent fb0b264 commit 3dd6ea5

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

packages/spec/src/system/auth.zod.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ export const DatabaseAdapterSchema = z.object({
324324

325325
export type DatabaseAdapter = z.infer<typeof DatabaseAdapterSchema>;
326326

327+
/**
328+
* Default field mappings for better-auth compatibility
329+
* These mappings bridge the gap between ObjectStack standard (Auth.js conventions)
330+
* and better-auth's field naming conventions
331+
*/
332+
export const BETTER_AUTH_FIELD_MAPPINGS = {
333+
session: {
334+
sessionToken: 'token',
335+
expires: 'expiresAt',
336+
},
337+
account: {
338+
providerAccountId: 'accountId',
339+
provider: 'providerId',
340+
},
341+
} as const;
342+
327343
/**
328344
* Database Field Mapping Configuration
329345
* Maps ObjectStack standard field names to driver-specific field names.
@@ -357,19 +373,13 @@ export const DatabaseMappingSchema = z.object({
357373
* Session model field mapping
358374
* Maps ObjectStack Session fields to driver fields
359375
*/
360-
session: z.record(z.string()).default({
361-
sessionToken: 'token',
362-
expires: 'expiresAt',
363-
}).describe('Session field mapping'),
376+
session: z.record(z.string()).default(BETTER_AUTH_FIELD_MAPPINGS.session).describe('Session field mapping'),
364377

365378
/**
366379
* Account model field mapping
367380
* Maps ObjectStack Account fields to driver fields
368381
*/
369-
account: z.record(z.string()).default({
370-
providerAccountId: 'accountId',
371-
provider: 'providerId',
372-
}).describe('Account field mapping'),
382+
account: z.record(z.string()).default(BETTER_AUTH_FIELD_MAPPINGS.account).describe('Account field mapping'),
373383

374384
/**
375385
* Verification token field mapping

0 commit comments

Comments
 (0)