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

Add ability to extend database session and use in session callback #7150

Open
camsloanftc opened this issue Apr 4, 2023 · 3 comments
Open
Labels
enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@camsloanftc
Copy link

camsloanftc commented Apr 4, 2023

Description 📓

Currently, as you can see here, only a subset of the session (from the database) is passed to the session callback.

Pasting here as well:

// packages/core/src/lib/routes/session.ts
const sessionPayload = await callbacks.session({
        // By default, only exposes a limited subset of information to the client
        // as needed for presentation purposes (e.g. "you are logged in as...").
        session: {
          user: {
            name: user.name,
            email: user.email,
            image: user.image,
          },
          expires: session.expires.toISOString(),
        },
        user,
      })

If I want to extend that session to add additional properties and use them within the session callback, I need to go back to the database with the sessionToken (which is not available within the session call so I end up needing to do a custom initializer to pass it in). It's not very efficient to do the extra database query, and the DX is a pain.

I would love to have the ability to extend which session fields we pass (maybe using a whitelist?), or better yet, we could just pass the session to the callback directly how we get it from the DB, and omit any unnecessary fields (like id for example).

How to reproduce ☕️

N/A

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

@camsloanftc camsloanftc added enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 4, 2023
@floppey
Copy link

floppey commented Apr 14, 2023

I'm trying to use next-auth with the patreonProvider and I believe this is what's stopping me from seeing if a user has made a pledge to my patreon account.

I was able to add the required scopes to get this information from patreon, but the user object accessible in the session only has the users name, email and image, and not the information I need about pledges.

@KATT
Copy link
Contributor

KATT commented Dec 19, 2023

I started a draft on this in #7150 as I also want/need to extend the session (at least with the ID, passing the token around feels scary)

@dimm0
Copy link

dimm0 commented Dec 23, 2024

Anybody solved this a year later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants