Authentication system
Ce contenu n’est pas encore disponible dans votre langue.
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 --filter=api auth:generate:
pnpm --filter=api 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 --filter=api auth:generateto scaffold missing entities/fields - Move the generated code into the entity files and register them in
db.config.ts - Run
pnpm --filter=api 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,apps/api/.env.example, and theBETTER_AUTH_SECRETfield fromapps/api/src/config/env.config.ts:
BETTER_AUTH_SECRET=- Remove leftover auth imports from example modules,
apps/api/src/test/helpers/, seeders,apps/web-spa/app/features/auth,apps/web-spa/app/lib/auth-client.ts, and the matching routes inapps/web-spa/app/routes.ts.