From 942f20facadfca0f2d9c0957e7304c6a48f85480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 26 Sep 2024 15:00:22 +0100 Subject: [PATCH] Update extending-the-session.mdx --- docs/pages/guides/extending-the-session.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/pages/guides/extending-the-session.mdx b/docs/pages/guides/extending-the-session.mdx index 70ead87778..35939bc00c 100644 --- a/docs/pages/guides/extending-the-session.mdx +++ b/docs/pages/guides/extending-the-session.mdx @@ -12,12 +12,16 @@ This is `name`, `email`, and `image`. A common use case is to add the user's id to the session. Below it is shown how to do this based on the session strategy you are using. + + By default, the `id` property does not exist on `token` or `session`. See the [TypeScript](https://authjs.dev/getting-started/typescript) on how to add it. + + ## With JWT To have access to the user id, add the following to your Auth.js configuration: ```ts filename="auth.ts" - providers, + // By default, the `id` property does not exist on `token` or `session`. See the [TypeScript](https://authjs.dev/getting-started/typescript) on how to add it. callbacks: { jwt({ token, user }) { if (user) { // User is available during sign-in @@ -39,16 +43,12 @@ Then, to expose the user's id in the actual session, you can access `token.id` i Calls to `auth()` or `useSession()` will now have access to the user's id. - - By default `id` property does not exists in `jwt`, see the [Typescript Docs](https://authjs.dev/getting-started/typescript) for more info. - - ## With Database If you are using a database session strategy, you can add the user's id to the session by modifying the `session` callback: ```ts filename="auth.ts" - providers, + // By default, the `id` property does not exist on `session`. See the [TypeScript](https://authjs.dev/getting-started/typescript) on how to add it. callbacks: { session({ session, user }) { session.user.id = user.id