npm install
npm start
-> server then runs on port 3000: http://localhost:3000
-> send hello
-> protected
You need to be authenticated. Sends a json upon success.
Content-Type: application/json
{
"username": "john",
"password": 42
}
Other credentials will fail
Logs the user out
- Go to / -> it works
- Go to /test -> 401 unauthorized
- POST /auth/login as above -> get the result of the
set-cookie
header. (It should be something like:connect.sid=s%3ADUIPwPJWFYTG63VBCoDE1wCOwxxaaZVU.SSEdlrRpjv0XB7WkjNNOOAMEUpYhFWsrZ7EUJ7dyMio; Path=/; HttpOnly
) - New request to GET /test but adds the header
cookie
with the previous thing -> It works, woohoo!
NOTE: doesn't work directly in the browser 'cause no html yet. Just send first request with the browser and others by hand with F12 > network, or Postman or https://addons.mozilla.org/en-US/firefox/addon/restclient/ or whatever.