title: React NextJS getServerSideProps not working?
body: <h1>While I was doing a discord oauth2, I wanted to save the data in the next iron session.</h1>
  <p>I used the <code>req.session.set(&quot;user&quot;, ...data)</code> and it saved when I checked.  Now the problem is with the <code>getServerSideProps</code>.</p>
  <p>This is my TSX getServerSideProps code</p>
  <pre class="lang-js prettyprint-override"><code>export const getServerSideProps: GetServerSideProps =
    withSession(unauthenticatedRoute);
  </code></pre>
  <p>This is the session code</p>
  <pre class="lang-js prettyprint-override"><code>import { withIronSession } from &quot;next-iron-session&quot;;
  import { NextIronHandler, NextRoute } from &quot;../typings/types&quot;;
  
  export function withSession(handler: NextIronHandler | NextRoute) {
    return withIronSession(handler, {
      password: process.env.COOKIE_SECRET,
      cookieName: &quot;session&quot;,
      ttl: 15 * 24 * 3600,
      cookieOptions: {
        secure: process.env.NODE_ENV === &quot;production&quot;,
        sameSite: &quot;strict&quot;,
        httpOnly: true,
      },
    });
  }
  </code></pre>
  <p>And this is the route code</p>
  <pre class="lang-js prettyprint-override"><code>export async function unauthenticatedRoute(
    ctx: GetServerSidePropsContext &amp; { req: { session: Session } }
  ) {
    const user = ctx.req.session.get(&quot;user&quot;);
  
    return {
      props: user ? { user } : {},
    };
  }
  </code></pre>
  <h1>When I used</h1>
  <pre class="lang-js prettyprint-override"><code>function HomePage({ user }: Props) {
     const router = useRouter();
  
    useEffect(() =&gt; {
      if (router.query.r) {
        location.replace(&quot;/&quot;);
      }
  
      console.log(user)
    }, []);
  }
  </code></pre>
  <p>It logged <code>undefined</code>, does anyone knows why?</p>