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