Is there a way to tell middleware that a page (App Router) is visited via client-side navigation?
Answered
Rough harvester ant posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Rough harvester antOP
Context:
In middleware, we’re doing auth checks, and this is an “expensive†process that ideally should only be called during a hard page visit. So we want to skip calling this middleware when a page is visited via client-side navigation. The
In middleware, we’re doing auth checks, and this is an “expensive†process that ideally should only be called during a hard page visit. So we want to skip calling this middleware when a page is visited via client-side navigation. The
next.config.js
skipMiddlewareUrlNormalize
doesn’t seem to be doing anything on app router.3 Replies
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/708a8637ada505b6b7a85972807d9dca.webp?size=256)
Alfonsus Ardani
you could check it via the headers
Answer
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/708a8637ada505b6b7a85972807d9dca.webp?size=256)
Alfonsus Ardani
using
headers().get('sec-fetch-dest') === 'document'
will endure that the the code runs only happens on hard reload![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Rough harvester antOP
cool, thanks I got it to work.