Files
main.tsmain
What you'll learn
- Register cookie-parser with a secret and read cookies from the request through a custom parameter decorator
- Set and clear cookies from a handler with @Res({ passthrough: true }), choosing httpOnly and the other options deliberately
- Explain what a signed cookie guarantees, and read one from signedCookies rather than cookies
Press Run tests to start the app. Its log appears here.Graded endpoints
A cat to be somebody's favourite
A second cat
No cookie yet, so the default
Sets a plain cookie; the body still comes from the handler's return value
The cookie came back and cookie-parser put it on request.cookies, where @Cookies('theme') found it
No signed cookie yet
A signed, httpOnly cookie carries her id and a signature only the server can compute
The signature matched, so cookie-parser put the value on signedCookies and @SignedCookies('favourite') found it
clearCookie sets the cookie again with a date in the past
The cookie is gone