Close the earlier lessons and build this from the brief.
The brief
- Settings (
/settings) has a Your name field and Save. Saving stores the name in a cookie and goes back to/. - The header says Hi, Ada once a name is saved, and Hi there before, on every page.
- The home page's heading is Welcome back, Ada, or Welcome.
GET /api/meanswers{ "name": "Ada" }, or{ "name": null }. The home page has an Ask the API button that shows The API knows you as Ada. or The API doesn't know your name yet.- Titles: the home page is Study Hub, and Settings is Settings · Study Hub.
Acceptance checks: press Ask the API first; save Ada in Settings; ask again.
Runs with real Next.js on your computer: unzip, then
npm install and npm run dev. Hint 1: the files
app/settings/page.jsx and app/settings/actions.js, app/api/me/route.js,
and a client component for the button. The layout reads the cookie for the
greeting.
Hint 2: route handlers and cookies
A route handler can call cookies() too, just as a page can.
Show one solution
Runs with real Next.js on your computer: unzip, then
npm install and npm run dev. Check yourself
- Which file makes
/api/me, and what does it export? - Which status code means "you sent something wrong"? Which means "created"?
- Why read a theme from a cookie on the server rather than from
localStorage?
Completion is saved in this browser only. It does not measure mastery.