title: Problems with AWS Amplify, Next.js and authenticated SSR
body: <p>I've got a Next.js application that uses AWS Cognito userpools for authentication.  I have a custom UI and am using the <code>aws-amplify</code> package directly invoking <code>signIn</code>/<code>signOut</code>/etc... in my code. (I previously used the AWS Hosted UI and had the same problem set out below - I hoped switching and digging into the actual APIs who reveal my problem but it hasn't)</p>
  <p>Everything in development (running on localhost) is working correctly - I'm able to login and get access to my current session both in a page's render function using</p>
  <pre><code>import { Auth } from 'aws-amplify';
  ...
  export default const MyPage = (props) =&gt; {
      useEffect(async () =&gt; {
          const session = await Auth.currentSession();
          ...
      }
      ...
  }
  </code></pre>
  <p>and during SSR</p>
  <pre><code>import { withSSRContext } from 'aws-amplify';
  ...
  export async function getServerSideProps(context) {
      ...
      const SSR = withSSRContext(context);
      const session = await SSR.Auth.currentSession();
      ...
  }
  </code></pre>
  <p>However, when I deploy to AWS Amplify where I run my staging environment, the call to get the current session during SSR fails.  This results in the page rendering as if the user is not logged in then switching when the client is able to determine that the user is in fact logged in.</p>
  <p>Current Hypothesis - missing cookies(??):</p>
  <p>I've checked that during the login process that the AWS cookies are being set correctly in the browser.  I've also checked and devtools tells me the cookies are correctly being sent to the server with the request.</p>
  <p>However, if I log out <code>context.req.headers</code> inside <code>getServerSideProps</code> in my staging environment, the cookie header is missing (whereas in my dev environment it appears correctly).  If this is true, this would explain what I'm seeing as <code>getServerSideProps</code> isn't seeing my auth tokens, etc... but I can't see why the cookie headers would be stripped?</p>
  <p>Has anyone seen anything like this before?  Is this even possible?  If so, why would this happen?  I assume I'm missing something, e.g. config related, but I feel like I've followed the docs pretty closely - my current conf looks like this</p>
  <pre><code>Amplify.configure({
      Auth: {...}
      ssr: true
  });
  </code></pre>
  <p>Next.js version is <code>11.1.2</code> (latest)</p>
  <p>Any help very much appreciated!</p>