Cody
Cody
BABetter Auth
Created by Cody on 3/16/2025 in #help
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"
}
}
9 replies