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 VexCollectionConfigusing Vex field builders. Server-only: pass the resultingVexAuthAdaptertodefineServerConfig({ server: { auth: { adapter } } }), which also uses itscollectionsas the source of truth to verify that the client config’sauthCollections— built by better-auth/src!betterAuthCollections from@vexcms/better-auth/client— have not drifted, throwingVexAuthConfigErrornaming 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→ fieldrequireddefaultValue→ fielddefaultValueunique/index→ fieldindex(index name:by_<field>_uniqueorby_<field>)references→relationshipfield- System fields get
admin.readOnly: trueandmeta.locked: true - Sensitive fields get
admin.hidden: true
Parameters
Section titled “Parameters”props?
Section titled “props?”— 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.
Returns
Section titled “Returns”A VexAuthAdapter ready for defineServerConfig({ server: { auth: { adapter } } }).
Example
Section titled “Example”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 }) }, },});