Skip to content

betterAuthAdapter

betterAuthAdapter(props?): VexAuthAdapter

Defined in: packages/better-auth/src/adapter.ts:109

Creates a Vex auth adapter from a Better Auth configuration.

Introspects Better Auth’s full merged schema (base fields + plugin fields

  • additionalFields) via getAuthTables() and converts each table into a standard Vex CollectionConfig using Vex field builders. Server-only: pass the resulting VexAuthAdapter to defineServerConfig({ server: { auth: { adapter } } }), which also uses its collections as the source of truth to verify that the client config’s authCollections — built by better-auth/src!betterAuthCollections from @vexcms/better-auth/client — have not drifted, throwing VexAuthConfigError naming the first divergence.

Mappings from Better Auth DBFieldAttribute to Vex fields:

  • type → Vex field type (string→text, boolean→checkbox, number→number, date/timestamp→date, json→text fallback, array→select)
  • required → field required
  • defaultValue → field defaultValue
  • unique/index → field index (index name: by_<field>_unique or by_<field>)
  • references → relationship field
  • System fields get admin.readOnly: true and meta.locked: true
  • Sensitive fields get admin.hidden: true

BetterAuthAdapterOptions

— Adapter options; pass your Better Auth config object wrapped in { config: authOptions }. Optional — when omitted, uses default Better Auth tables with no plugins or additional fields.

VexAuthAdapter

A VexAuthAdapter ready for defineServerConfig({ server: { auth: { adapter } } }).

vex.config.server.ts
import { betterAuthAdapter } from "@vexcms/better-auth";
import { defineServerConfig } from "@vexcms/core";
import { authOptions } from "~/auth/server";
import vexConfig from "./vex.config";
export default defineServerConfig({
config: vexConfig,
server: {
auth: { adapter: betterAuthAdapter({ config: authOptions }) },
},
});