The `validation-better-auth` package provides a flexible and extensible validation plugin specifically designed for the `better-auth` framework. It enables developers to integrate API request validation using various schema definition libraries such as Zod, Valibot, and ArkType. It also supports Yup by internally wrapping Yup schemas to a standard format. This package is currently at version 1.3.4 and shows an active development cadence with frequent patch releases addressing build, module, and type resolution issues. Its key differentiator is its tight integration with `better-auth` and its adapter pattern, allowing for broad compatibility with different validation schema libraries rather than enforcing a specific one.
npm install validation-better-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate the `validation-better-auth` plugin into the `better-auth` framework, using Zod schemas for request body validation on specific API paths, including `before` and `after` hooks.
Ensure your `tsconfig.json` and build tools are configured for modern module resolution (e.g., `"module": "NodeNext"`, `"moduleResolution": "NodeNext"`) and verify imports are using ESM syntax for recent Node.js versions.
Always install `better-auth` and `validation-better-auth` such that their peer dependency ranges are satisfied. Check the `package.json` for compatible versions.
For new projects, consider using a 'standard' schema library like Zod or Valibot to leverage direct integration. If using Yup, ensure `YupAdapter` is correctly imported and applied.
Check your `tsconfig.json` for `module` and `moduleResolution` settings. For modern Node.js, set them to `"NodeNext"` or `"ESNext"`. Ensure your build process transpiles correctly if targeting older environments.
Switch to ESM import syntax: `import { validator } from 'validation-better-auth'`. If forced to use CommonJS, ensure your bundler (e.g., Webpack, Rollup) is configured to handle ESM interop correctly, or transpile your code.For each object in the `validator` plugin array, ensure it has either `schema: YourSchemaInstance` or `adapter: YourAdapter(YourSchemaInstance)` defined for the specific `path`.