Not able to get session type while using auth.api.getSession({headers: headers()})

I have an turborepo setup with below packages, i am trying to migrate from "next-auth" to "better-auth". I have all auth related code in seperate internal package "packages/auth".

I facing very strange issue on which i am stuck from last 2 days. My problem is related to getting types for session, I am using auth.api.getSession to get session on serverside.

I have tried everything, even when i am using this in auth.ts file itself it is not giving types. I have tried to use differnt tsconfig.

Please help me.


My packages:

{
  "next": "14.2.1-canary.0",
"typescript": "5.2.2",
"better-auth": "^1.2.5",
"@trpc/server": "11.0.0-rc.332",
"drizzle-orm": "0.40.0",
"pg": "^8.13.0",
"@neondatabase/serverless": "^0.7.2",
}



usage:
export const session = await auth.api.getSession({ header: headers() });

type of session object:
const session: {
    [x: string]: any;
}



type of auth.api.getSession on hovering .getSession:
(property) getSession: <boolean>(context: {
    headers: Headers;
    query?: {
        disableCookieCache?: boolean | undefined;
    } | undefined;
    asResponse?: boolean | undefined;
}) => Promise<{
    [x: string]: any;
}> & {
    ...;
}



my tsconfig:
{
    "$schema": "https://json.schemastore.org/tsconfig",
    "display": "Default",
    "compilerOptions": {
        "composite": false,
        "declaration": true,
        "declarationMap": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "inlineSources": false,
        "isolatedModules": true,
        "moduleResolution": "node",
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "preserveWatchOutput": true,
        "skipLibCheck": true,
        "strict": true,
        "strictNullChecks": true
    },
    "exclude": ["node_modules"]
}
Was this page helpful?