Fullstack CourseLearn by building
Back to week 3

Topic

Notes API — Auth + list craft milestone

Definition

Milestone P3 proves cookie JWT auth, RBAC, paginated { data, meta } lists, and soft deletes with consistent counts on the Notes API.

In simpler words

Understand how to secure Notes with cookie JWT, RBAC, pagination, and soft deletes.

Maps to Week 3 auth and API craft. Follow standard cookie JWT + RolesGuard patterns.

After this you can

  • Login that sets httpOnly cookie; JwtAuthGuard + RolesGuard
  • Return paginated meta with page/limit/total/totalPages
  • Soft-delete with matching list and count filters

What this stage covers

Definition

This stage is a Notes API build slice: read the official Nest chapter, understand the matching Nest concepts, then take the quiz to lock it in.

In simpler words

Score ≥80% on the quiz below to save roadmap progress — exactly like every other topic.

Official docs: Nest Authentication + Authorization — https://docs.nestjs.com/security/authentication

Key Nest pieces to understand: the auth module, role/auth decorators, and paginated list querying

Supplemental Nest/SQL links live under /resources.

Optional practice: rebuild the same slice for Notes in your own workspace to cement the pattern.

What a correct build includes

- [ ] httpOnly cookie login
- [ ] @Roles('admin') on delete + ForbiddenException path
- [ ] { data, meta } pagination + soft-delete filters

Use this as the acceptance checklist while you study the concepts and answer the quiz.

Deliverables

Definition

Deliverables are the concrete Nest files and behaviors a correct version of this stage produces.

In simpler words

Aim for the smallest vertical slice that satisfies these — not a sprawling redesign.

Cookie JWT login; @Public on login/health

Admin-only soft delete; member ownership on update

Paginated list excluding soft-deleted rows in data and total

Keep in mind

  • 401 = not authenticated; 403 = authenticated but wrong role.
  • Reuse the same QueryBuilder filters for page and count.

Test

Check your understanding

At least 10 questions — mix of concept, syntax, practical, and logic. Score ≥80% (enforced by the API) to save progress.

Checking your session…

15 questions · concept 5 · syntax 3 · practical 4 · logic 3

1. What does Notes P3 add?
Concept
2. How do you prove P3?
Syntax
3. What status for logged-in member lacking admin?
Practical
4. Why cookie JWT over localStorage here?
Logic
5. What must soft-delete list math do?
Concept
6. Is UI hiding authorization for P3?
Practical
7. What list response shape is required?
Syntax
8. Should body.role authorize deletes?
Logic
9. What does soft-delete-safe mean for counts?
Concept
10. Which P3 approach is wrong?
Practical
11. Why httpOnly for the notes auth cookie?
Conceptintermediate
res.cookie('access_token', token, { httpOnly: true, sameSite: 'lax' });
12. A logged-in member calls this. What status must they receive?
Syntaxadvanced
@Roles('admin')
@Delete(':id')
remove() {}
13. What is the pagination bug here?
Practicaladvanced
const [data] = await repo.findAndCount({ where: { deletedAt: null }, take, skip });
const total = await repo.count();
14. Why return this shape for P3?
Logicintermediate
return { data, meta: { page, limit, total, totalPages } };
15. Why is this authorization wrong for P3?
Conceptadvanced
if (req.body.role === 'admin') return this.svc.remove(id);

Checking your session…