title: Nextjs Auth0 get data in getServerSideProps
body: <p>Im using Auth0 to authenticate users.</p>
  <p>Im protected api routes like this:</p>
  <pre class="lang-js prettyprint-override"><code>// pages/api/secret.js
  
  import { withApiAuthRequired, getSession } from '@auth0/nextjs-auth0';
  
  export default withApiAuthRequired(function ProtectedRoute(req, res) {
    const session = getSession(req, res);
    const data = { test: 'test' };
    res.json({ data });
  });
  </code></pre>
  <p>My problem is when I'm trying to fetch the data from getServerSideProps I'm getting 401 error code.</p>
  <p>If I use useEffect Im able to get data from api route.</p>
  <p>Im trying to fetch the data like this:</p>
  <pre class="lang-js prettyprint-override"><code>export const getServerSideProps = withPageAuthRequired({
    async getServerSideProps(ctx) {
      const res = await fetch('http://localhost:3000/api/secret');
      const data = await res.json();
  
      return { props: { data } };
    },
  });
  </code></pre>
  <p>Im getting the following response:
  error: &quot;not_authenticated&quot;, description: &quot;The user does not have an active session or is not authenticated&quot;</p>
  <p>Any idea guys? Thanks!!</p>