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

Issue with Merging Guest User into SSO Authenticated User #1022

Open
lukevella opened this issue Feb 8, 2024 · 0 comments
Open

Issue with Merging Guest User into SSO Authenticated User #1022

lukevella opened this issue Feb 8, 2024 · 0 comments

Comments

@lukevella
Copy link
Owner

Description

We've identified an issue in our SSO authentication flow where a user is authenticated before they are created in the database. This results in an incorrect assignment of polls to the user.

Details

During the first-time SSO login, the mergeGuestsIntoUser function is called to assign any existing guest polls to the newly authenticated user. However, at this point in the process, the user has not yet been created in the database. As a result, the polls are assigned a user_id value that corresponds to the provider_account_id, not the actual user_id.

This incorrect assignment necessitates a second merge operation further down the line to reassign the polls to the correct user_id once the user has been created in the database.

Expected Behavior

The expected behavior is that during the first-time SSO login, after the user is authenticated, the user should be created in the database. Only then should the mergeGuestsIntoUser function be called to assign any existing guest polls to the newly authenticated user. The polls should be assigned the correct user_id value at this time, eliminating the need for a second merge operation.

Suggested Fix

This is a complex issue that requires a deep understanding of how next-auth works and could potentially require significant changes in how authentication works in the app. Difficulty arises due to the fact that guest sessions are currently being handled through next-auth which means when a user authenticates the contents of the session cookie is overwritten which limits the window in which we are able to identity which guest session should be attributed to the newly authenticated user. A solution could be to separate the two so that guest sessions run in parallel to next-auth sessions. This should allow us to perform the merge at a part of the authentication flow when the user is guaranteed to have been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant