Closed didemkkaslan closed 5 months ago
@didemkkaslan, sorry to hear this is happening after migrating to v6. Just to make sure I understood this correctly, you said that every route is being called via the middleware when you're only trying to sign in via the /login
route? Was any of this behavior happening in v5, or only after you upgraded (even if sporadically)?
@cwomack I wasn't using middleware before we had client side auth hoc. I wanted to implement serverside auth but v5 didn't quite work well with middleware so I decided to migrate to v6. Yes you are correct in development everything works well but when deployed ( we use amplify hosting ) middleware is being called for every route initially. When I hit /login route it goes like
/login / /register
So I've removed middleware.ts and instead did it for every protected page in getServerSideProps and it works well both locally and prod. But I really want to use middleware to handle this Idk whats wrong
@didemkkaslan, appreciate the patience on a response for this issue. That's great to hear that it is working if the middleware is removed, and it helps isolate the issue to the middleware I think. When you enable the middleware, what is the expected redirect order? And is there more code for the middleware beyond what was provided in the original issue description?
Also, do you have any redirect rules/logic set up through Amplify Hosting by chance?
Closing this issue as we have not heard back from you. If you are still experiencing this, please feel free to reply back and provide any information previously requested and we'd be happy to re-open the issue.
Thank you!
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
I've done the steps for migrating to amplify v6. Have an issue with authentication handled by middleware. Sometimes
signIn
gets stuck and the login page is frozen. This only happens on production. Actually signIn works correctly so I can see isSignedIn is equal to true and nextStep.signInStep is DONE. but still its somehow stuckAnd I don't know if its normal but console logging the request.nextUrl.pathname in middleware is like below. Its being called for every route even if I only hit /login route.
Expected behavior
signIn should redirect the user to / route
Reproduction steps
// On Login Form Submit
// middleware
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response