Skip to Content
Delmare Digital

Types

TypeScript types for the Payload instance with Better Auth attached, hooks and endpoints, and the generated Better Auth schema.

Payload with Better Auth

import type {
  PayloadWithAuth,
  PayloadRequestWithBetterAuth,
  BetterAuthReturn,
  CollectionHookWithBetterAuth,
  EndpointWithBetterAuth,
  RoleArray,
  WithRoleField,
} from '@delmaredigital/payload-better-auth'
  • PayloadWithAuth is a Payload instance with betterAuth attached. Cast getPayload() to it to reach payload.betterAuth.api or payload.betterAuth.handler.
  • PayloadRequestWithBetterAuth, CollectionHookWithBetterAuth and EndpointWithBetterAuth type requests, hooks and endpoints that use it.
  • WithRoleField<User, 'roles', string[]> moves the generated role property to a custom role field.

Generated schema types

import type {
  User, BetterAuthSession, Account, Verification,
  Apikey, Passkey, Organization, Member, Invitation, Team, TeamMember, TwoFactor,
} from '@delmaredigital/payload-better-auth'

These are generated from Better Auth's schema for the plugins the package's type generation covers. ModelKey, PluginId and BetterAuthFullSchema are exported as well.

Option types

PayloadAdapterConfig, BetterAuthCollectionsOptions, BetterAuthPluginOptions, BetterAuthPluginAdminOptions, BetterAuthStrategyOptions, SessionHelperOptions, FirstUserAdminOptions, ApiKeyPermissionsConfig, ApiKeyPermissionConfig, PermissionCheck, RoleCheckConfig, SelfAccessConfig, FieldUpdateConfig and MigrateStringifiedArraysOptions are exported for typing your own wrappers.

Your Payload types

After adding a Better Auth plugin, regenerate your Payload types so payload-types.ts includes the new collections and fields:

payload generate:types
Edit this page on GitHub

On this page