Build an app with duck-auth
WIPAn eight-chapter course that builds the sign-in for one notes app, from a first password check to a production deployment
This course builds the authentication for DuckNotes, a small notes app, one chapter at a time. Every chapter adds to the same source tree, and every snippet runs as shown against @gentleduck/auth.
What you build
By the end, people sign up, verify their address, sign in with a password, a mailed link or GitHub, add a TOTP second factor, and must step up before a destructive action. It all runs on Postgres and Valkey behind a strict() production check.
The roadmap
Part 1 drives the engine from a script, so every answer is printed. Part 2 puts it behind HTTP and a browser, then hardens it.
Course map
| Chapter | Topic | What you learn |
|---|---|---|
| 1 | Your first sign-in | createAuth, identities, passwords, signIn, resolveSession, AuthError |
| 2 | Accounts | deliver, email verification, password reset, events |
| 3 | Sessions | The row, deadlines, rotation, devices, hijack detection |
| 4 | Behind HTTP | Auth routes over auth.flows, sign-up, CSRF, errorToHttp |
| 5 | In the browser | fetch calls to your routes, the error envelope, the CSRF cookie |
| 6 | More ways in | Magic links, GitHub OAuth, account linking |
| 7 | A second factor | TOTP enrollment, backup codes, step-up to AAL 2 |
| 8 | Production | Postgres, Valkey, strict(), tests |
Prerequisites
- TypeScript and
async/await. - Node.js 22 or newer, or Bun.
- No database until chapter 8, which uses Postgres and Valkey.
Setup
Create the project
mkdir ducknotes && cd ducknotes
npm init -y
npm pkg set type=module
mkdir src
Install duck-auth
npm i @gentleduck/auth @node-rs/argon2
@node-rs/argon2 is the password hasher's peer. Everything else is installed by the chapter that needs it.
Add a runner
npm i -D tsx
npx tsx src/main.ts
Start
How the chapters are written
Each chapter has learning goals, a diagram of what it introduces, the code, what just happened inside the engine, and a try it exercise. New concepts link to their reference page.
@gentleduck/auth 5.13.0. Import paths come from the package exports map: @gentleduck/auth/core, @gentleduck/auth/adapters/memory, @gentleduck/auth/server/express and so on.See also
- Introduction: the same ground as reference.
- Quick start: one Express file, without the tour.
- Concepts: the terms the course uses.