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

chore(docs): documentation for extending session data with provider functions #11138

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
25 changes: 25 additions & 0 deletions docs/pages/guides/extending-the-session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ This is `name`, `email`, and `image`.
a database or external APIs.
</Callout>

## With provider functions

We can extend the default session data in a few ways, one of which is by using the `authorize` and `profile` functions. These functions let us return a user object with the properties we need. We can then create logic based on this information to search in a database or an external API.

```ts
import Github from "next-auth/providers/github";
import Credentials from "next-auth/providers/credentials";
import type { Provider } from "next-auth/providers";

const providers: Provider[] = [
Google({
halvaradop marked this conversation as resolved.
Show resolved Hide resolved
clientId: process.env.AUTH_GOOGLE_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
async profile(profile) {
return { ...profile }
},
}),
Credentials({
async authorize(credentials) {
return { ...credentials }
}
})
]
```

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.

## With JWT
Expand Down
Loading