Step 10
Notice the URL for homepage will be appended with the message query parameter:
http://localhost:5001/?message=Incorrect username or password
This is not the most elegant way of achieving the desired behavior. Imagine we have more detailed error messages (and perhaps other properties to pass along the message). The query parameter is not the place to send these messages.
We will now introduce an alternative approach to achieve the same results. This alternative strategy uses web cookies!
Web cookies (or simply cookies) are simple text files that a website can store on your browser.
Stop the application and install the cookie-parser package:
npm install cookie-parser
Open index.js
, import the cookie-parser module:
const cookieParser = require("cookie-parser");
Then, add this module as a middleware to your express app:
app.use(cookieParser());