Whenever I try to use the getServerSesssion
function with all the necessary parameters, it results in a type error. In my code, I have the getServerAuthSession
function defined as shown below:
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import type { GetServerSidePropsContext } from 'next';
import { getServerSession } from 'next-auth/next';
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext['req'];
res: GetServerSidePropsContext['res'];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
However, when attempting to make this call, I encounter the following type error:
The argument provided '[IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }, ServerResponse<IncomingMessage>, { adapter: Adapter; providers: OAuthConfig<...>[]; secret: string | undefined; cookies: { ...; }; callbacks: {}; }]' does not match the expected parameter of type 'GetServerSessionParams<GetServerSessionOptions>'.
The structure '[IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }, ServerResponse<IncomingMessage>, { adapter: Adapter; providers: OAuthConfig<...>[]; secret: string | undefined; cookies: { ...; }; callbacks: {}; }]' is not compatible with '[IncomingMessage & { cookies: Partial<{ [key: string]: string; }>; }, ServerResponse<IncomingMessage>, GetServerSessionOptions]'.
There is an issue with the second type element.
The provided type '{ adapter: Adapter; providers: OAuthConfig<GoogleProfile>[]; secret: string | undefined; cookies: { sessionToken: { name: string; options: { httpOnly: boolean; sameSite: string; path: string; domain: string; secure: boolean; }; }; }; callbacks: {}; }' does not align with the expected type 'GetServerSessionOptions'.
The detailed errors indicate a mismatch within different adapter properties and configurations.
I have followed the configuration guidelines outlined in the documentation available here: https://next-auth.js.org/configuration/nextjs
If anyone has any insights or suggestions, they would be greatly appreciated.