Skip to content
Backend

NestJS auth API

Register, verify, log in, refresh with rotation and reuse detection, reset passwords and manage roles, on NestJS, Prisma and MySQL, tested end to end.

$10Version 1.0.0

How buying works: message me on WhatsApp, pay by OMT or Whish, and I send you the repository within one working day.

NestJSPrismaMySQLZod

Screenshots

  • The API reference of the NestJS auth API on a desktop screen, in light mode
  • The API reference of the NestJS auth API on a phone
  • The API reference of the NestJS auth API on a desktop screen, in dark mode

The reference is generated from the template’s own code, and the walkthrough is a recording of it running.

Walkthrough

The auth flow, request by request, recorded against the template running: every response in it is what the API answered. The video is silent; its steps are listed beside it.

What the video shows

  1. Register: the account is created and a verification link is emailed.
  2. Log in before verifying: refused, email_not_verified.
  3. The verification email, printed in the terminal in development.
  4. Verify the address with the token from the link.
  5. Log in: an access token and a refresh token.
  6. Call a protected route with the access token.
  7. Refresh: a new pair, and the old refresh token is used up.
  8. Replay the old refresh token: refresh_token_reused, and the whole session ends.
  9. The newest access token stops working too: session_revoked.
  10. Guess passwords: past the limit, 429 rate_limited.

What is inside

  • src/auth — register, verify the email address, log in and out, refresh-token rotation with reuse detection, password reset
  • src/users — your account, password change and sessions; admin routes for accounts and roles
  • Access tokens that stop working the moment their session ends, not when they expire
  • Rate limits, Zod validation, and one error shape with machine-readable codes
  • openapi.json generated from the code, Swagger UI at /docs, and a static API reference
  • prisma/schema.prisma with its migration, a seed, and a Docker Compose MySQL
  • Unit tests, and end-to-end tests against a real MySQL database in CI

What's in the zip

  • .github/workflows/ci.yml
  • docker/mysql-init/
  • prisma/schema.prisma
  • prisma/migrations/
  • screenshots/
  • scripts/build-docs.mjs
  • src/auth/
  • src/users/
  • src/common/
  • src/openapi/
  • src/mail/
  • test/
  • .env.example
  • compose.yaml
  • openapi.json
  • CHANGELOG.md
  • LICENSE.md
  • README.md
  • package.json

What you need

  • Node.js 22.12 or later, and npm
  • MySQL 8 (a Docker Compose file starts it)
  • An SMTP server, to send real emails

Licence

One developer, unlimited projects of your own and your clients’. You may deliver it inside the projects you build; you may not resell or share the template itself, or use it to make a template product. Updates for twelve months.

The full terms are in LICENSE.md, which comes with the template. Ask me for a copy before you buy.

Questions people ask

What am I allowed to do with a template?

One developer can use it in as many projects as they like, their own and their clients’. You may not resell or share the template itself, changed or not, or use it to make a template product of your own.

Do I get updates?

Yes, for twelve months from purchase. When a new version comes out, I send it to you.

Is there support?

On WhatsApp or by email, with your licence key, and I answer within one working day. Support covers the template working as described. It does not cover writing your features for you.