Server session untyped

We're currently in the process of migrating an AuthJS monorepo to better-auth, but off the bat are experiencing the returned value of a server side getSession being untyped.
const session: {
[x: string]: any;
}
const session: {
[x: string]: any;
}
ts: 5.7.3
better-auth: 1.2.4
ts: 5.7.3
better-auth: 1.2.4
We were able to create a minimal reproduction using a fresh Turborepo which we can share if required. Details from minimal repoduction:
import { betterAuth } from "better-auth";

export const auth = betterAuth({});

// returns untyped
const session = await auth.api.getSession({
headers: new Headers(),
});

// works
export type Session = typeof auth.$Infer.Session;
import { betterAuth } from "better-auth";

export const auth = betterAuth({});

// returns untyped
const session = await auth.api.getSession({
headers: new Headers(),
});

// works
export type Session = typeof auth.$Infer.Session;
Minimal TS config in order of inheritance.
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"plugins": [
{
"name": "next"
}
]
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
"next.config.js",
".next/types/**/*.ts"
],
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
"exclude": ["node_modules"]
}
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"plugins": [
{
"name": "next"
}
]
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
"next.config.js",
".next/types/**/*.ts"
],
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
"exclude": ["node_modules"]
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"incremental": false,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
"moduleDetection": "force",
"moduleResolution": "NodeNext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"incremental": false,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
"moduleDetection": "force",
"moduleResolution": "NodeNext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
}
}
6 Replies
Cody
CodyOP2mo ago
Anyone else running into this?
avvo
avvo2mo ago
it may help to just share the reproduction i'm using better auth in a monorepo with no issues
Cody
CodyOP2mo ago
We're finding it's on all repositories. I've forked Bekacru/create-t3-turbo (because it'd be a known working state w/ turbo) which is available at codylittle/create-t3-turbo Within packages/auth/src/index.ts we have the following: The only changes made to the repository are updating the package manager used to match our prod systems
No description
Cody
CodyOP2mo ago
Additionally having ts config errors not liking "module": "Preserve",
Aziz
Aziz2mo ago
I have the same issue, it’s still unresolved for me, we manually typed it and moved on for now
Cody
CodyOP2mo ago
So testing on a fresh install of windows right now, working completely fine tried uninstalling all vscode extensions too - given its working on diff PC, I'm probably going to go with global dependency resolution somewhere

Did you find this page helpful?