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

208
Visualizações
Typeof session in getServerSideProps in NextJS with next-auth

I am implementing dashboard page with credentials flow with NextJS and next-auth, I have I have augmented type of session in next-auth.d.ts as per the docs https://next-auth.js.org/getting-started/typescript#module-augmentation like so

import NextAuth from "next-auth";

declare module "next-auth" {
  interface Session extends NextAuth.DefaultSession {
    user: {
      id: string;
      email: string;
    };
  }
}

and it works as expected everywhere client side. Now I need to get the session data in getServerSide props so I follow this example https://next-auth.js.org/configuration/nextjs#unstable_getserversession and although I should get type I have set I get the oryginal DefaultSession type which is

export interface DefaultSession extends Record<string, unknown> {
    user?: {
        name?: string | null;
        email?: string | null;
        image?: string | null;
    };
    expires: ISODateString;
}

and I get errors because it tries to strigify undefineds in name and image and when I try to log session.id server side in GetServerSide props I get undefined.

This is my GetServerSideProps:

export const getServerSideProps: GetServerSideProps = async (context) => {
  const session = await unstable_getServerSession(
    context.req,
    context.res,
    authOptions
  );

  if (!session) {
    return {
      redirect: {
        destination: "/",
        permanent: false,
      },
    };
  }

  return {
    props: {}, // will be passed to the page component as props
  };
};

Thanks for any help

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