Skip to content

Commit

Permalink
update post
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Mar 31, 2024
1 parent 6f41a7a commit d797f12
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/posts/middleware-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ app.get("/", (req, res) => {
});
```

One common response I get is that using middleware prevents developers from accidentally forgetting to add an auth check. **That's why you test your code** for anything serious. You should be testing your auth logic regardless of your implementation. Given that, adding auth checks to each route is less bug-prone and easier to debug than forcing an abstraction with middleware.
This doesn't mean middleware is useless. It works for global-level stuff like CSRF protection and providing data to each route. But even then, you should probably replace it once you need to deal with exceptions and multiple patterns.

One common response I get to this opinion is that using middleware prevents developers from accidentally forgetting to add an auth check. **That's why you test your code**. You should be testing your auth logic regardless of your implementation. Given that, adding auth checks to each route is less bug-prone and easier to debug than forcing an abstraction with middleware.

0 comments on commit d797f12

Please sign in to comment.