Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda