Next.js SSR: true - Error: Invalid Refresh token calling currentAuthenticatedUser server side when user pool Device Tracking is set to opt-in #11664
Labels
Auth
Related to Auth components/category
feature-request
Request a new feature
Next.js
SSR
Issues related to Server Side Rendering
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
When rendering server-side with next, when the access token in no longer valid but refresh token is, amplify fails on calling
SSR.Auth.currentAuthenticatedUser()
with errorError: Invalid Refresh Token
. Before the access token expires everything works both client and server side, and even with expired access token everything is refreshed as it should on client side, but doesn't work server side.This seems to happen only when Device Tracking is not set to 'don't remember' (only tried with that and with opt-in option, don't know the behaviour for 'always remember'). This happens for users who have not 'opted in' to device tracking, in fact the only reason why we had it set that way was that it was the Cognito default when creating the pool through AWS console.
The reason we tried toggling the device tracking was this comment - without it, we were just looking into why the refresh token works client side and not server side.
Expected behavior
Would expect SSR Auth to work even with opt-in device tracking, mainly when the users have not opted in. Or for it to work the same way client and server side. I understand from this issue that the access token can't be updated from server (yet), but would expect the token to be refreshed on the server and the separately on the client.
If this is expected behaviour with such option, then it may simply need extra documentation, or a better error message.
Reproduction steps
You can see the amplify config of our project here, the call to
currentAuthenticatedUser
is here which is used in almost everygetServerSideProps
to forward user data to page props (like here)But I suspect the same behaviour should show on a empty project, calling
currentAuthenticatedUser
with cognito user pool . We have configured the cognito pool and client 'by hand' (from aws console) before we started using the aws-amplify lib, in case this may make a difference.Code Snippet
Log output
aws-exports.js
No response
Manual configuration
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: