I have an authentication flow with Sign up, Login and Home page.
Sign up and Login pages should not be accessible after successful login. And after successful Login, the user redirects to Home page.
The problem is if I click back button in the browser, I'm going back to the Login page. But if I do a hard refresh there(in Login page) I get redirected to the Home page as expected and now even if I try to go back by clicking browser back button, it automatically redirects me to the Home page.
Why before hard reload I was able to go to Login page even though it is protected in middleware?
const isPublicRoute = publicRoutes.some((prefix) =>
request.nextUrl.pathname.startsWith(prefix)
);
if (session && isPublicRoute) {
const absoluteURL = new URL("/", request.nextUrl.origin);
return NextResponse.redirect(absoluteURL);
}```
This is my middleware.
Any help would be much appreciated!