Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda