Authentication system
The authentication system is handled by the Better Auth library, which provides most features you will ever need, plus some more.
Better-auth is heavily plugin-based, we propose a few guides on how to add some specific features like organizations, admin, etc.
❓ How it works
Section titled “❓ How it works”Better-auth is using your database to store all of its data. Depending on the ORM you use, you might need to create some entities to store the data.
We use MikroORM in this boilerplate, and you can find the entities in the auth module.
The boilerplate ships a custom MikroORM adapter for Better Auth (see auth-db.adapter.ts), replacing the community better-auth-mikro-orm package. It includes a CLI integration to auto-generate entity code via pnpm auth:generate:
pnpm auth:generate # auth generate --config src/modules/auth/auth.cli.mts --yesWhen adding a Better Auth plugin:
- Add the plugin in
auth.config.ts - Run
pnpm auth:generateto scaffold missing entities/fields - Move the generated code into the entity files and register them in
db.config.ts - Run
pnpm db:migrate:createto create the MikroORM migration - Run auth tests to verify alignment
📝 How to use
Section titled “📝 How to use”Better-auth provides server and client methods, see the Better Auth documentation for more details.
Better-auth provides a OpenAPI schema and a live documentation of your API endpoints. You can find it at http://localhost:3000/api/auth/reference by default.
🧹 How to remove
Section titled “🧹 How to remove”- Delete the
authmodule fromapps/api/src/modules/auth - Remove the AuthModule from
apps/api/src/app.module.ts - Remove the following dependencies from
apps/api/package.json:
"better-auth","auth"- Remove the following dependencies from the frontend apps
"better-auth",- Remove the following env variables from
apps/api/.env:
BETTER_AUTH_SECRET=