How to augment Session using TypeScript?
See original GitHub issueYour question
Hi, would it be possible to add an example of type augmentation to the documentation?
What are you trying to do
I’ve modified what the session object returns and would like to augment the type defined in next-auth and next-auth/client to reflect the changes I’ve made. I’ve tried overriding the type definition by creating a next-auth.d.ts at the root of the project and included it in my tsconfig.json. However, VSCode uses the one defined by the module and not the one I’ve created (even though it recognizes that there are two type definitions).
To show what I have, here’s the type definition I’ve created:
// next-auth.d.ts
import 'next-auth'
import NextAuth from 'next-auth'
import * as auth from 'next-auth'
// import * as client from 'next-auth/client'
// import 'next-auth/client'
declare module 'next-auth' {
export * from 'next-auth'
export type InitOptions = auth.InitOptions
export default NextAuth
interface Session {
user: {
name: string
email: string
image: string
uid: string
}
}
}
declare module 'next-auth/client' {
export * from 'next-auth/client'
export interface Session {
user: {
name: string
email: string
image: string
uid: string
}
}
}
Any help would be appreciated.
Thank you.
Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:29 (7 by maintainers)

Top Related StackOverflow Question
I’ve just recently made the
Usermodel augmentable with@types/next-auth, by adding anauth.d.tsfile with the contents below:@sualko Try the following: