Next.js Discord

Discord Forum

Next Middleware + Parallel Routes issue

Unanswered
kazii posted this in #help-forum
Open in Discord
I have developed a custom backend that utilizes OTP verification for user authentication. To enhance user experience, I've implemented parallel routes, so when a user attempts a restricted action without being logged in, an OTP verification modal is displayed. Once the user verifies the OTP, the backend sets a session ID in a cookie and sends it to the client, successfully completing the authentication process.

Furthermore, I've incorporated middleware to ensure proper authentication, which redirects users to the appropriate pages. However i'm facing this issue where in my middleware if user is not logged in im redirecting him to login?redirect=requestedPath and post login on the client side the url is not getting replaced with the redirect url.

I would appreciate any insights or suggestions on how to improve this process or if there's a better way to handle the authentication flow. Thank you for your assistance.

0 Replies