diff --git a/docs/docs/getting-started/typescript.md b/docs/docs/getting-started/typescript.md index 5afce328b7..a31ae8ca85 100644 --- a/docs/docs/getting-started/typescript.md +++ b/docs/docs/getting-started/typescript.md @@ -15,7 +15,7 @@ Check out the [Database Adapters: TypeScript](/getting-started/adapters#typescri ## Module Augmentation -Auth.js libraries come with certain interfaces that are shared across submodules and different Auth.js libraries (For example: `next-auth` and `@auth/prisma-adapter` will rely on types from `@auth/core`). +Auth.js libraries come with certain interfaces that are shared across submodules and different Auth.js libraries (For example: `next-auth` and `@auth/prisma-adapter` will rely on types from `@auth/core/types`). Good examples of such interfaces are `Session` or `User`. You can use TypeScript's [Module Augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to extend these types to add your own properties. @@ -40,7 +40,7 @@ Let's look at `Session` for example: // auth.ts import NextAuth, { type DefaultSession } from "next-auth" -declare module "@auth/core" { +declare module "@auth/core/types" { /** * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context */ @@ -66,7 +66,30 @@ export const { auth } = NextAuth({ - TODO SvelteKit + +```ts +// app.d.ts +import type { DefaultSession } from '@auth/core/types'; + +declare module '@auth/core/types' { + /** + * Returned by `useSession`, `getSession`, and the callbacks session function. + */ + interface Session extends DefaultSession { + user: { + /** The user's postal address. */ + adddress: string; + + /** + * By default, TypeScript merges new interface properties and overwrite existing ones. + * In this case, the default session user properties will be overwritten, with the new one defined above. + * To keep the default session user properties, you need to add them back into the newly declared interface. + */ + } & DefaultSession['user']; + } +} +``` + TODO SolidStart @@ -81,7 +104,7 @@ export const { auth } = NextAuth({ Module augmentation is not limited to specific interfaces. You can augment almost anything, but here are some of the more common interfaces that you might need to override in based on your use-case: ```ts -declare module "@auth/core" { +declare module "@auth/core/types" { /** * The shape of the user object returned in the OAuth providers' `profile` callback, * or the second parameter of the `session` callback, when using a database.