Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add warning for missing type #11912

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading