Closed jporsay closed 1 year ago
Hi @jporsay thanks for opening this issue.
Auth.currentAuthenticatedUser()
shouldn't not make a network request unless you pass in { bypassCache:true }
. However Im curious how you are analyzing that a network request is being made?
@nadetastic Given that timing currentAuthenticatedUser
shows durations between 600ms and 2s (which is what my usual latency with Cognito is), my assumption was that there's an HTTP request being made, however we aren't bypassing cache and adding NODE_DEBUG=http
environment variable doesn't show any HTTP call being made, which confuses me as to why that latency.
An interesting thing is that a second invocation of the currentAuthenticatedUser
within the same request takes 0ms.
Having said that, our expectation would be that currentAuthenticatedUser
was an almost instant call with a valid JWT.
We are using an authenticated session, yes.
And they shouldn't be expired credentials, since this is consistent with every request. We have an API that is used for filtering options in a list and every request done to it after user input (think writing 'fr', waiting a second, api request is made taking an extra ~600ms due to currentAuthenticatedUser
, continue writing 'free', waiting a second, another api request is made with the extra time).
The browser tab shows no requests besides the single API request and the latency is reported server-side.
Got it @jporsay, where do you have this hosted (ex Amplify hosting)? And is it the same experience when running a build locally? Im curious if the latency is more specific to the execution on the backend/server.
This happens both in localhost as well as within our host (Vercel).
Got it @jporsay, thanks for confirming. This looks related to aws-amplify/amplify-js#8918, and will update this title to reflect the issue better. So far I don't believe that Auth.currentAuthenticatedUser
making a network request.
aws-amplify/amplify-hosting#3855
Closing this issue to consolidate and track on aws-amplify/amplify-hosting#3855
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
Whenever I call
Auth.currentAuthenticatedUser
within SSR, I notice that there's an HTTP request being done, not sure where and what for.Expected behavior
My expectation is that on Server-side requests, cognito uses available information from cookies and the operation is instant, therefore, no HTTP requests are made since I'm only interested on refreshing if the token has expired (not the case since it happens on every request).
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