-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetchAuthSession is slow in nextjs(v14) middleware #14079
Comments
Hi @ganesh-cidc thanks for opening this issue, currently the fetchAuthSession does the following to return a valid session
The step 1 requires fetching the JWKs from your Cognito User Pool endpoint, and current there is a known issue that the JWKs is being excessively being fetched which adds unnecessary latency. We've implemented a fix and it's expected to be release soon. Please following the linked issue for updates. Step 2 is required to ensure the client persisted user session can be refreshed. Step 3 is optional as I mentioned, if you are not expecting to use AWS credentials on your server side, e.g. not using IAM with the GraphQL category or using the Storage category, you don't need to configure the identity pool with Amplify. So it will be skipped. |
@ganesh-cidc Yes, that's the correct PR |
@pranavosu @HuiSF It seems the PR is merged. Can you create a new release for it. I will test it from my side and update here |
@ganesh-cidc, we have the PR merged and will have it included in the next release. We'll follow up with a comment as soon as the release is out (which will be very soon). |
Hey @ganesh-cidc we are planning to release the fix soon, in the meantime if you are willing to test it, you can install the npm install aws-amplify@unstable @aws-amplify/adapter-nextjs@unstable |
@HuiSF It seems the stable version of 6.11.0 is released. I have updated to them.
I can notice the improvements after the update. The function call for fetchAuthSession in middleware has been reduced from around 300ms to less than 50ms. Thanks for this. Closing the issue |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Other
Environment information
Describe the bug
When using the fetchAuthSession function within middleware, it takes approximately 300-350ms for each call & sometimes more than that. This leads to a noticeable delay in routing, resulting in a sluggish user experience.
I have removed the fetchAuthSession and tried checking auth status based on if the cookie is available and it is very fast. I have setup in amplify in nextjs based on the docs here
Using nextjs 14.2.14 and testing in production build locally
Expected behavior
fetchAuthSession to resolve quickly for subsequent calls
Reproduction steps
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
The text was updated successfully, but these errors were encountered: