middleware.js Doesn’t Fire in Subsequent Route with Next/Link
I’ve encountered an issue with next/Link
while using middleware.js
for authenticate and authorization .The problem arises When I click on header links ,which trigger a request to the server to retrieve the user’s profile .Initially the middleware checks if the user exists ;if not ,it redirects the user to /auth
. After authenticating in the app ,I click on the /profile
link in header ,but it doesn’t work for the subsequence requests using <Link href="/profile"> profile </Link>
and still in /auth
route .however if I use <a href="/profile"> profile </a>
,everything works as expected.
middleware dosent fire in subsequnce route with next/link
I’ve encountered an issue with next/Link
while using middleware.js
for authenticate and authorization .The problem arises When I click on header links ,which trigger a request to the server to retrieve the user’s profile .Initially the middleware checks if the user exists ;if not ,it redirects the user to /auth
. After authenticating in the app ,I click on the /profile
link in header ,but it doesn’t work for the subsequence requests using <Link href="/profile"> profile </Link>
.however if I use <a href="/profile"> profile </a>
,everything works as expected.
The page isn’t redirecting properly how to solve
I want to restricts both user home and admin dashboard when only login then open otherwise redirect to login or admin login page.