Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
React NextJS getServerSideProps not working?

While I was doing a discord oauth2, I wanted to save the data in the next iron session.

I used the req.session.set("user", ...data) and it saved when I checked. Now the problem is with the getServerSideProps.

This is my TSX getServerSideProps code

export const getServerSideProps: GetServerSideProps =
  withSession(unauthenticatedRoute);

This is the session code

import { withIronSession } from "next-iron-session";
import { NextIronHandler, NextRoute } from "../typings/types";

export function withSession(handler: NextIronHandler | NextRoute) {
  return withIronSession(handler, {
    password: process.env.COOKIE_SECRET,
    cookieName: "session",
    ttl: 15 * 24 * 3600,
    cookieOptions: {
      secure: process.env.NODE_ENV === "production",
      sameSite: "strict",
      httpOnly: true,
    },
  });
}

And this is the route code

export async function unauthenticatedRoute(
  ctx: GetServerSidePropsContext & { req: { session: Session } }
) {
  const user = ctx.req.session.get("user");

  return {
    props: user ? { user } : {},
  };
}

When I used

function HomePage({ user }: Props) {
   const router = useRouter();

  useEffect(() => {
    if (router.query.r) {
      location.replace("/");
    }

    console.log(user)
  }, []);
}

It logged undefined, does anyone knows why?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!