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

201
Views
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
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!