#It depends on your authentication logic
1 messages · Page 1 of 1 (latest)
thank you. But what other authentication logic could i have ? What do you need to now about my structure ? With middleware solution won't I have too many requests ? every page, url request, i will have to check if I'm authenticated
With middleware you can filter out which pages need to be protected and which don't. Don't worry about running it on each request, it doesn't impact your page load speeds in a significant way.
What you need to do essentially is check if there is an auth cookie on the request, and if there is allow access to the route.
You can control which routes need to be protected with an array like this ['/secret-page', ...] and on each middleware call check if the pathname matches one of the entries in that list. If it doesn't forward the request, and if it does check for the cookie presence and act accordingly.