I’m using a Turborepo monorepo with a Next.js 15 App Router project (apps/web) and a shared packages/types package that contains my NextAuth module augmentation.
However, TypeScript still gives this error:
Property 'id' does not exist on type '{ name?: string | null; email?: string | null; image?: string | null }'
This happens in my NextAuth route (apps/web/src/app/api/auth/[...nextAuth]/route.ts):
if (session.user) {
session.user.id = token.sub!;
}
Folder structure
my-turborepo/
│
├── tsconfig.json
│
├── apps/
│ └── web/
│ ├── package.json
│ ├── tsconfig.json
│ └── src/app/api/auth/[...nextAuth]/route.ts
│
└── packages/
└── types/
├── package.json
├── tsconfig.json
└── next-auth.d.ts
📄 packages/types/next-auth.d.ts
import { DefaultSession } from "next-auth";
declare module "next-auth" {
interface Session {
user: {
id: string;
} & DefaultSession["user"];
}
interface User {
id: string;
}
}
declare module "next-auth/jwt" {
interface JWT {
id: string;
}
}
export {};
📄 packages/types/tsconfig.json
{
"compilerOptions": {
"composite": true,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["./**/*.d.ts"]
}
📄 packages/types/package.json
{
"name": "@repo/types",
"version": "1.0.0",
"types": "./next-auth.d.ts"
}
📄 apps/web/package.json
"dependencies": {
"@repo/types": "workspace:*",
"@repo/db": "workspace:*",
"next": "15.5.6",
"next-auth": "^4.24.13",
"react": "19.1.0",
"react-dom": "19.1.0"
}
📄 apps/web/tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{ "name": "next" }],
"paths": {
"@/*": ["./src/*"]
},
"typeRoots": [
"../../packages/types",
"./node_modules/@types"
]
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"../../packages/types/**/*.d.ts"
],
"exclude": ["node_modules"]
}
📄 root/tsconfig.json
{
"files": [],
"references": [
{ "path": "apps/web" },
{ "path": "packages/types" }
],
"compilerOptions": {
"composite": true
}
}
The actual NextAuth route
apps/web/src/app/api/auth/[...nextAuth]/route.ts
import NextAuth, { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
})
],
callbacks: {
async session({ session, token }) {
if (session.user) {
session.user.id = token.sub!;
}
return session;
}
}
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
Despite everything, TypeScript still does not merge the module augmentation, and I still get:
Property 'id' does not exist on type 'Session["user"]'
Question
What am I missing?
How can I get NextAuth module augmentation to work in a TurboRepo monorepo with a shared packages/types folder?