Utilities
Smaller exports — withBetterAuthDefaults, detectAuthConfig, permission generation and the stringified-array migration.
withBetterAuthDefaults
withBetterAuthDefaults(options) applies defaults to Better Auth options and returns them. Today it sets one: trustedOrigins: [baseURL] when baseURL is set and trustedOrigins is not. An explicit trustedOrigins is left as is, so multi-domain setups keep working.
import { withBetterAuthDefaults, createBetterAuthPlugin, payloadAdapter } from '@delmaredigital/payload-better-auth'
createBetterAuthPlugin({
createAuth: (payload) => betterAuth(withBetterAuthDefaults({
database: payloadAdapter({ payloadClient: payload }),
baseURL: process.env.BETTER_AUTH_URL,
// trustedOrigins becomes [process.env.BETTER_AUTH_URL]
})),
})migrateStringifiedArrays
A one-time migration for databases written by 0.11.3 or earlier, where array fields were stored as JSON strings.
import { migrateStringifiedArrays } from '@delmaredigital/payload-better-auth'
const results = await migrateStringifiedArrays({ payload, betterAuthOptions, dryRun: true })Prop
Type
When to run it, and how to verify the result, is in Upgrading to 0.12.
Other exports
| Export | What it does |
|---|---|
detectAuthConfig | Reports whether the config has a users collection with auth.disableLocalStrategy, which is what triggers admin component injection. auth: true does not count. |
generateCollectionPermissions | Builds the API key permission definitions (read / write per collection) the admin view shows. |
detectEnabledPlugins | From @delmaredigital/payload-better-auth/management. Reports which Better Auth plugins are enabled in a set of options. |
firstUserAdminHooks | The first-user-admin logic as Better Auth database hooks. Pass roleField directly. |
getRoleField, DEFAULT_ROLE_FIELD | The configured role property, and its default 'role'. |
useAuthMountPath, useAuthClientBaseURL | From @delmaredigital/payload-better-auth/components. Derive the Better Auth mount from the live Payload config in admin components. |

