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 sub to defaultJwtPayload for credentials provider. #1725

Merged

Conversation

dogomedia-github
Copy link
Contributor

What:
The default jwt payload for the credentials provider is missing the sub field. This fix adds the sub field to the jwt payload, making it consistent with the jwt payload for the oauth and email providers.

Why:
The sub is missing when using jwt sessions and credentials provider. This means that users can only be identified by their email and not by the sub value.

How:

In src/server/routes/session.js:

Change

    const defaultJwtPayload = {
      name: user.name,
      email: user.email,
      picture: user.image
    }

to

    const defaultJwtPayload = {
      name: user.name,
      email: user.email,
      picture: user.image,
      sub: user.id?.toString()
    }

Checklist:

  • Documentation - NA
  • Tests - NA
  • Ready to be merged

It's a single line code change, so should be a pretty safe change.

@vercel
Copy link

vercel bot commented Apr 14, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/HgFrKv9sXSSSoeZoMpDYUgFefLiG
✅ Preview: https://next-auth-git-fork-dogomedia-fix-credentials-jwt-pa-81912e.vercel.app

@vercel vercel bot temporarily deployed to Preview April 14, 2021 18:02 Inactive
@github-actions github-actions bot added the core Refers to `@auth/core` label Apr 14, 2021
@Joaovsa7
Copy link

Can you update your branch? it's out-of-date with the base branch.

@jcdogo jcdogo force-pushed the fix/credentials-jwt-payload-sub branch from 816c9e4 to b214959 Compare April 14, 2021 20:57
@vercel vercel bot temporarily deployed to Preview April 14, 2021 20:58 Inactive
@dogomedia-github
Copy link
Contributor Author

@Joaovsa7 Ok, I've updated the branch.

@dogomedia-github

This comment has been minimized.

@balazsorban44
Copy link
Member

don't see how that would block anything. just use the jwt callback to add an ID for the time being.
Read the docs please: https://next-auth.js.org/configuration/callbacks#jwt-callback

At its best, this PR is just a convenience change.

@balazsorban44 balazsorban44 merged commit ae26df0 into nextauthjs:main Apr 20, 2021
@github-actions
Copy link

🎉 This PR is included in version 3.15.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants