fix: persist user ID across before-user-created hook for external providers (#41309) - #2680
Open
abhinavlevi wants to merge 1 commit into
Open
fix: persist user ID across before-user-created hook for external providers (#41309)#2680abhinavlevi wants to merge 1 commit into
abhinavlevi wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
When users sign up via external providers (OAuth/SSO), the
before-user-createdhook payload receives a generateduser.idthat is subsequently discarded and re-generated during account creation.As a result, the UUID sent in the webhook payload differs from the
idstored inauth.users.Closes supabase/supabase#41309
What is the new behavior?
The candidate
user.IDgenerated prior to invoking thebefore-user-createdhook is now persisted inUserProvidedDataand reused during user creation in PostgreSQL. The webhook payloaduser.idandauth.users.idare now guaranteed to match for all OAuth/SSO providers.Additional context
Problem Breakdown
triggerBeforeUserCreatedExternal(internal/api/hooks.go) callsparams.ToUserModel(...), which generates a UUID for the candidate user model and sends it in the webhook payload.createAccountFromExternalIdentity(internal/api/external.go) calledparams.ToUserModel(...)a second time undercase models.CreateAccount:, overwritinguser.IDwith a second UUID before saving to PostgreSQL.Solution
UserID uuid.UUIDtoUserProvidedData(internal/api/provider/provider.go).userData.UserID = user.IDintriggerBeforeUserCreatedExternal.userData.UserIDincreateAccountFromExternalIdentityifuserData.UserID != uuid.Nil.Verification
Ran the integration test suite locally against PostgreSQL: