amplify-js: SSR: ReferenceError: window is not defined

Describe the bug I am testing the new SSR capabilities with next.js and I am seeing:

ReferenceError: window is not defined
    at UniversalStorage.setUniversalItem (/node_modules/@aws-amplify/core/lib/UniversalStorage/index.js:88:21)
    at UniversalStorage.setItem (/node_modules/@aws-amplify/core/lib/UniversalStorage/index.js:69:22)
    at CognitoUser.cacheTokens (/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:1412:18)
    at /node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:1391:17
    at /node_modules/amazon-cognito-identity-js/lib/Client.js:127:31

To Reproduce Follow steps in tutorial here https://docs.amplify.aws/start/getting-started/data-model/q/integration/next Connect with auth and sign in with cognito.

Expected behavior window is not used on the server.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (6 by maintainers)

Most upvoted comments

@m5r At this moment, the supported use-case is Auth happening on the client so credentials can be shared with the server.

In your example, you’re attempting to do the authentication on the server, which we’re still solving for. That would make it a feature request, but this use-case seems different than what’s happening for @oste.

@oste #6813 (comment) makes it sound like you were specifying a custom storage adapter. That won’t be necessary with Amplify.configure({ ...awsexports, ssr: true }).

Is Authentication on the server made available now?

@m5r At this moment, the supported use-case is Auth happening on the client so credentials can be shared with the server.

In your example, you’re attempting to do the authentication on the server, which we’re still solving for. That would make it a feature request, but this use-case seems different than what’s happening for @oste.

@oste https://github.com/aws-amplify/amplify-js/issues/6813#issuecomment-695056643 makes it sound like you were specifying a custom storage adapter. That won’t be necessary with Amplify.configure({ ...awsexports, ssr: true }).