Next.js Discord

Discord Forum

middleware not triggered always

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Avatar
Giant pandaOP
i am working on authentication in my app when i logs in the app redirects to home/chats page i have implemented middleware to prevent the user from going back to the login page however the middleware doesn't seem to get triggered , if i refresh the home/chats page and try to navigate back to login page the middleware works and i am redirected to home/chats page as expected .

2 Replies

Avatar
thats because of the browser cache. The browser caches the response for X seconds (30 seconds by default) and shows you the caches result, when you are within these seconds.

It's a normal browser feature. You can either completely disable the browser cache via: https://nextjs.org/docs/app/api-reference/next-config-js/staleTimes
Or wait 30 seconds so it refreshes the browser cache
Avatar
@Giant panda solved?