-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp-neededThe maintainer needs help due to time constraint/missing knowledgeThe maintainer needs help due to time constraint/missing knowledge
Description
Describe the bug
Signing in with email and then signing in with an OAuth provider creates two separate users when using JWT sessions.
It should be noted that I only tested this issue with an OAuth provider that does not grant access to the user's email address
Steps to reproduce
https://github.com/RobertCraigie/next-auth-multiple-user-bug
- Sign in with email
- Sign in with Bungie
Expected behavior
One user is created and the OAuth account is linked to said user.
Screenshots or error logs
https://imgur.com/a/sI2pNzp
Additional context
I have traced the root cause of this issue to
| if (session && session.user) { |
This block of code expects the decoded JWT to have a user property when it does not.
A simple fix is to add the user property in the JWT callback
...
callbacks: {
jwt: async (token, user, account, profile, isNewUser) => {
const isSignIn = user ? true : false;
if (isSignIn) {
token.user = { id: user.id }
}
return Promise.resolve(token);
}
},
...Feedback
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
iaincollins, nyedidikeke, lukel97, rorhug, fromi and 4 moremickaelmangaudiaincollins, fromi, shadoath and noclat
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp-neededThe maintainer needs help due to time constraint/missing knowledgeThe maintainer needs help due to time constraint/missing knowledge