Skip to main content

Installation

1. Install the packages​

Install better-auth and @strapi-community/plugin-better-auth together:

npm install better-auth @strapi-community/plugin-better-auth
# or
yarn add better-auth @strapi-community/plugin-better-auth
# or
pnpm add better-auth @strapi-community/plugin-better-auth
note

You must to be running Strapi 5.45.0 or higher.

2. Enable the plugin​

Add the plugin to your Strapi plugin configuration:

config/plugins.ts
export default {
'better-auth': {
enabled: true,
},
};

3. Create a Better Auth config file​

Create a Better Auth configuration file that uses the Strapi adapter:

src/lib/auth.ts
import { betterAuth } from 'better-auth';
import { strapiAdapter } from '@strapi-community/plugin-better-auth';

export const auth = betterAuth({
database: strapiAdapter(),
trustedOrigins: ['http://localhost:3000'],
advanced: {
database: {
generateId: 'serial',
},
},
});
note

The generateId: "serial" option tells Better Auth to use auto-incremented integer IDs, which aligns with Strapi's default document ID strategy.

4. Generate the schema​

The plugin does not register any content types automatically. You must run the Better Auth CLI to generate the Strapi schema files:

npx auth generate

5. Start Strapi​

Start Strapi in development mode. The generated content types will be picked up and registered:

pnpm develop

The Better Auth API is now available at http://localhost:1337/api/auth/.