After the day
Where to take it next
Eight things to do after Friday, in the order I would do them — each a short brief rather than a lab.
In this chapter
- Eight directions, in the order I would take them
- Where tokens fit, and what they cost you
- What to do first if you only do one
Four hours gets you a working API, a page that reads it, a login, and tests that run on every push. What follows is what I would build next, roughly in this order. None of these is a lab. Each is a paragraph and a direction.
If you are reusing this with your own students, these also make reasonable semester projects: pick one per pair.
1. Finish the web app
The page reads fares but cannot add one — every fare you created on Friday
went in through curl. Build the form: sign in, then show an add-a-fare form
only when GET /api/me succeeds, and hide it again after logout. It is a
small piece of work that forces a real question: what should the page do while
it does not yet know whether you are signed in?
2. Tokens, for the mobile app that does not exist yet
We used a session cookie, and for a browser app that is the right default:
the browser sends it automatically, httpOnly keeps scripts away from it, and
logging out actually ends the session because the server forgets it.
A phone has no cookie jar. That is where a JSON Web Token fits: the API
signs a small token saying who you are and when it expires, the app sends it
as Authorization: Bearer …, and the server verifies the signature without
looking anything up.
Note what you give up. A session can be revoked — delete it server-side and the next request fails. A JWT cannot be taken back. Once signed it is valid until it expires, so “log out” on the phone only deletes the app’s copy. Real systems answer that with short-lived tokens plus a refresh token, or a deny-list of revoked ones, which is a database lookup again — the thing the token was meant to avoid.
So the honest shape is: keep sessions for the web app, add tokens when a client cannot hold a cookie. The password hashing from Lab C does not change either way.
3. Migrations instead of db push
npm run setup uses prisma db push, which makes the database match the
schema and keeps no history. That is right for a workshop and wrong for
anything with real data in it. Switch to prisma migrate dev: each change
becomes a numbered SQL file you commit, review and apply to a server in the
same order. The day you need to add a column to a table holding a term’s fares
without destroying them, you will want that file.
4. Roles, not just logins
requireLogin answers who are you. It does not answer may you do this.
Right now any signed-in user can change any fare. Add requireRole, and then
face the harder question underneath: is “fare officer” a property of the
person, or of the person for a particular route or region? A clerk in
Basse probably should not be setting fares for Banjul. That question is where
most permission models quietly go wrong.
5. Keep the history you already have
The data model never updates a fare — it inserts a new row with a date. That
means the whole history is sitting in the table already. Build a page that
shows it: what this trip cost through the year, when it changed, and who
entered each figure. Add enteredBy pointing at the user, and a fare stops
being a number and becomes a record with an author.
6. Put it somewhere
Deploy the API and a managed Postgres, and point a real domain at it. The
things that will bite, in the order they will bite: DATABASE_URL as a real
environment variable rather than a file, secure: true on the session cookie
behind HTTPS, running migrations as part of the deploy, and a session store
that is not a Map in one process — because the moment there are two servers,
half your requests will not recognise the cookie.
7. Make it work on a cheap phone
The page is plain HTML and CSS, which is already most of the way there. Test it on a real mid-range Android phone on mobile data, not on a laptop with the window made small. Then ask what happens on a bad connection — a spinner that never resolves, or a message that says what went wrong and offers a retry. That is the difference between software that is usable at a car park and software that is usable at a desk.
8. Audit what a model gave you
This one is an hour, not a project, and it is the one I would set as homework.
Take Lab B’s handler and ask whatever tool you use to write it from scratch —
an Express route that accepts a new bus fare and validates it — without
showing it this repository. You will get something that works. Then go
looking for what it could not possibly have known: that stop 1 is Westfield
and stop 8 is Brikama, that a route runs one way so the pair is ordered, that
status is sample or verified and means something to a bursar, that a
fare is inserted and never updated because March’s receipts must stay true.
None of that is a flaw in the tool. It is the shape of the thing: it cannot know your context, and it will not tell you that it does not. Write down each gap you find and which of the five moves would have closed it — most of them are move 2, Constrain. That list is the most useful page of notes you will take home, and it is the exercise to run with your own students first.
Where to stop
Not every one of these is worth doing. If you only do one of the builds, do the first — a feature nobody can reach from the page is a feature that does not exist yet. If you only do one thing at all, do number 8.