This package provides a plugin for the `better-auth` library, enabling highly customizable credentials-based authentication. It allows developers to integrate `better-auth` with virtually any backend authentication system, such as Rails, Django, custom APIs, or LDAP, while leveraging `better-auth`'s existing session management infrastructure. Currently at version 0.1.8, the library is in active development, meaning minor versions may introduce breaking changes to its API. Key differentiators include the ability to define flexible input schemas using Zod for robust validation, store arbitrary custom data (like JWTs or permissions) directly within `better-auth` sessions, configure auto sign-up features, and set custom session expiry per authentication method. It offers a comprehensive solution for adapting diverse authentication logic to the `better-auth` ecosystem.
npm install better-auth-custom-credentialsVerified import paths — ran on the pinned version, not inferred.
Demonstrates client-side setup for `better-auth-custom-credentials`, including extending the auth client, signing in with custom credentials, and retrieving session data.
Review the official GitHub repository for the latest API documentation and migration guides when updating versions. Pin exact versions in `package.json` to prevent unexpected breaks.
Ensure your `verify` implementation consistently returns an object with an `ok` boolean, an optional `reason` (for failures), and `user` and `meta` (for success) to be picked up by Better Auth's session management.
Modify your `createAuthClient` configuration to always pass `{ credentials: 'include' }` in the `fetch` options: `createAuthClient({ fetch: (url, init) => fetch(url, { ...init, credentials: 'include' }) })`.Always provide a comprehensive `z.object()` schema to the `inputSchema` property of `credentialsPlugin` to define and validate all expected input fields from the client-side form.
Ensure you are using ECMAScript Modules (ESM) import syntax: `import { credentialsPlugin } from 'better-auth-custom-credentials';`.Review your server-side `inputSchema` and ensure the client-side `signIn.credentials` method is sending an object with the exact keys and types expected by the schema.
Install the required peer dependencies: `npm install better-auth zod` or `pnpm add better-auth zod`.
Ensure the `user` object returned from `verify` includes all mandatory fields (e.g., `id`, `email`, `name`) that your `better-auth` configuration expects for a `User`.