Skip to content

Commit

Permalink
docs: add warning for missing type (#11912)
Browse files Browse the repository at this point in the history
* docs: add warning for missing type

* Update extending-the-session.mdx

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
Jay-Karia and balazsorban44 authored Sep 26, 2024
1 parent 5e5a7fc commit 532761a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/pages/guides/extending-the-session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Callout type="info">
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.
</Callout>

## 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
Expand All @@ -44,7 +48,7 @@ Calls to `auth()` or `useSession()` will now have access to the user's id.
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
Expand Down

0 comments on commit 532761a

Please sign in to comment.