auth
auth copied to clipboard
Manual identity linking doesn't update user_metadata properly in the newly issued token
Bug report
- [x] I confirm this is a bug with Supabase, not with my own application.
- [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
On manual social identity linking, the user_metadata properties like iss, sub, provider_id in the newly issued token are reset to the first provider instead of getting the new provider's values.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Create a user, say, using Google
- (Optional for clarity) Logout and login using, say, an OTP or password. The token will have
amr[0].method= "otp" (or "password"), butuser_metadata.isswill still be "https://accounts.google.com" (along with Google's sub and provider_id). This is expected since user_metadata persists the OAuth provider data from signup, andamr[0].methodcorrectly indicates the current authentication method. - Link another social identity by calling
supabase.auth.linkIdentity({ provider: 'discord' }) - This results in a new jwt token
amr[0].method= "oauth", butuser_metadata.iss,subandprovider_idstill have the values of the google provider. - Logout and login with the new identity (discord) -
user_metadata.issis set to "https://discord.com/api" as expected (as well assubandprovider_id)
Expected behavior
After manual identity linking the newly issued token should be properly attributed to the new provider, the same as on a login with that provider.
Code Reference
Bug location: (presumably) linkIdentityToUser() function Missing call: targetUser.UpdateUserMetaData(tx, identityData) should be added