Skip to content

fix: persist user ID across before-user-created hook for external providers (#41309) - #2680

Open
abhinavlevi wants to merge 1 commit into
supabase:masterfrom
abhinavlevi:fix/oauth-hook-user-id-mismatch
Open

fix: persist user ID across before-user-created hook for external providers (#41309)#2680
abhinavlevi wants to merge 1 commit into
supabase:masterfrom
abhinavlevi:fix/oauth-hook-user-id-mismatch

Conversation

@abhinavlevi

@abhinavlevi abhinavlevi commented Aug 6, 2026

Copy link
Copy Markdown

What is the current behavior?

When users sign up via external providers (OAuth/SSO), the before-user-created hook payload receives a generated user.id that is subsequently discarded and re-generated during account creation.

As a result, the UUID sent in the webhook payload differs from the id stored in auth.users.

Closes supabase/supabase#41309

What is the new behavior?

The candidate user.ID generated prior to invoking the before-user-created hook is now persisted in UserProvidedData and reused during user creation in PostgreSQL. The webhook payload user.id and auth.users.id are now guaranteed to match for all OAuth/SSO providers.

Additional context

Problem Breakdown

  1. triggerBeforeUserCreatedExternal (internal/api/hooks.go) calls params.ToUserModel(...), which generates a UUID for the candidate user model and sends it in the webhook payload.
  2. createAccountFromExternalIdentity (internal/api/external.go) called params.ToUserModel(...) a second time under case models.CreateAccount:, overwriting user.ID with a second UUID before saving to PostgreSQL.

Solution

  1. Added UserID uuid.UUID to UserProvidedData (internal/api/provider/provider.go).
  2. Captured userData.UserID = user.ID in triggerBeforeUserCreatedExternal.
  3. Reused userData.UserID in createAccountFromExternalIdentity if userData.UserID != uuid.Nil.

Verification

Ran the integration test suite locally against PostgreSQL:

go test -v ./internal/api -run "TestExternal|TestSignup"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

before-user-created webhook sends different ID than is actually solved in Auth for SSO providers

1 participant