Skip to content

Commit 18cf904

Browse files
committed
fix: check unuathorised usernames
1 parent 93a05ea commit 18cf904

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • middleware-exercises/custom-middleware

middleware-exercises/custom-middleware/server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ app.use(parseJSONArrayBody);
7272
* The handler only needs to build the response — all validation is done.
7373
*/
7474
app.post("/", (req, res) => {
75+
if (!req.username) {
76+
return res
77+
.status(401)
78+
.send(`You're not authenticated. Please, provide a username`);
79+
}
80+
7581
// Authenticate if a username is provided
76-
const authLine = req.username
77-
? `You're authenticated as ${req.username}`
78-
: `You're not authenticated!`;
82+
const authLine = `You're authenticated as ${req.username}`;
7983

8084
// build subject based on count
8185
const count = req.body.length;

0 commit comments

Comments
 (0)