You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Google Provider the library seems to fail in generating a proper providerAccountId, issuing a new one for every login. Which causes weird behavior from the second login onwards.
How to reproduce
Configure a project using the database session option and the Google Provider.
Do NOT use the prompt: "consent" option
Turn debug on
Now login for the first time
Go into the database, and take note your account providerAccountId. We will use it later.
Logout
Login again
Notice that you will get OAuthAccountNotLinked
Search in the debug logs for authorization result -> account -> providerAccountId
Notice how it does not match the providerAccountId on the database
Since the providerAccountIds do not match the code fails to find a matching account for that provider, but since the user exists it assumes it was created with another provider, causing the issue.
Expected behavior
The providerAccountId should match the existing account
The second login should work properly
Workaround to make everything work
Expected behavior can be achieved by using the following configuration:
Google({
(...)
profile: async (profile) => {
return {
...profile,
id: profile.sub, // If you don't do this, signing in, then signing out, then signing in again will NOT work
};
}),
Why the workaround works?
The above seems to map the userFromProfile.id here properly to the Google sub on the Oauth return causing it to be consistent across executions and work as expected.
What would be a possible solution?
The solution seems to be for the library to map (for Google) the profile ID to the User sub from Google
Probably this file should have a default profile configuration such as:
The above was NOT tested and is merely a suggestion based on what I found in my debugging. I lack the necessary knowledge of this codebase to propose a proper solution. Take this as a mere starting point for what I THINK is the cause.
The text was updated successfully, but these errors were encountered:
Provider type
Google
Environment
Reproduction URL
https://github.com/lucas-subli/authjs-12807
Describe the issue
When using Google Provider the library seems to fail in generating a proper providerAccountId, issuing a new one for every login. Which causes weird behavior from the second login onwards.
How to reproduce
providerAccountId
. We will use it later.result
->account
->providerAccountId
providerAccountId
on the databaseExpected behavior
providerAccountId
should match the existing accountWorkaround to make everything work
Expected behavior can be achieved by using the following configuration:
Why the workaround works?
The above seems to map the userFromProfile.id here properly to the Google sub on the Oauth return causing it to be consistent across executions and work as expected.
What would be a possible solution?
The text was updated successfully, but these errors were encountered: