supabase / auth

A JWT based API for managing users and issuing JWT tokens
https://supabase.com/docs/guides/auth
MIT License
1.56k stars 376 forks source link

supabase.auth.linkIdentity does not return raw_user_meta_data #1708

Open chanmathew opened 3 months ago

chanmathew commented 3 months ago

Bug report

Describe the bug

When calling supabase.auth.linkIdentity using the JS client, it does not return and store the raw_user_meta_data that you would normally get when using supabase.auth.signInWithOAuth:

CleanShot 2024-08-04 at 16 06 01@2x

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Sign in an anonymous user
  2. Try to link identity with supabase.auth.linkIdentity
  3. Check the raw_user_meta_data in auth.users

Expected behavior

It should return the metadata just like an oauth sign in.

Screenshots

When using supabase.auth.signInWithOAuth, it returns the raw_user_meta_data: CleanShot 2024-08-04 at 16 08 06@2x

When using supabase.auth.linkIdentity, it does not return it: CleanShot 2024-08-04 at 16 06 01@2x

System information

Additional context

It would be best if it can be returned as I want my postgres trigger to automatically add the full_name and avatar_url to my public.profiles table once the user's anonymous account has been converted to a permanent account once they've signed in.

j4w8n commented 3 months ago

My apologies... commenting again, because my previous one was from the test account.

How are you getting the screenshot output? I tried this with hosted Supabase, looked in the auth.users table in the dashboard, and the user metadata was there for the user. I also console.log'd the returned data from the linkIdentity method, and it also showed the user metadata.

chanmathew commented 3 months ago

@j4w8n I'm getting it in the authentication section, and then looking for my user: CleanShot 2024-08-04 at 23 02 50@2x

Then I click on view user info: CleanShot 2024-08-04 at 23 03 06@2x

It's also empty in the actual auth.users table: CleanShot 2024-08-04 at 23 10 36@2x

I've tried both local dev and in the cloud dashboard, seems like the raw_user_meta_data is empty in both.

j4w8n commented 3 months ago

I'm sorry. I misunderstood what you were saying. I now understand that you mean the metadata that comes back from the OAuth provider.

After converting the user, if I logout and log back in with OAuth, then the data is there, but it would be nice if that data came back during the conversion.

Based on what I see in the data.url of a conversion, it's authorizing directly to the OAuth provider:

'https://github.com/login/oauth/authorize?client_id=<redacted>&redirect_to=http%3A%2Flocalhost%3A5173%2Fself&redirect_uri=https%3A%2F%2F<redacted>.supabase.co%2Fauth%2Fv1%2Fcallback&response_type=code&scope=user%3Aemail&skip_http_redirect=true&state=<redacted>'

Versus an OAuth login data.url:

https://<redacted>.supabase.co/auth/v1/authorize?provider=github&redirect_to=http%3A%2F%2Flocalhost%3A5173%2Fauth%2Fcallback%3Fnext%3D%2Fapp&code_challenge=l3tDoN9qS2u2B3rLXGidmfDcQRga9h3tbhM-w_U21FU&code_challenge_method=s256

I tried to work around it by adding something like ?refresh=true to the redirectTo option on linkIdentity, so I could refresh the session myself, but the redirect never happens - I assume because it's authorizing directly to the provider, and in this case, I couldn't find any redirect url settings for GitHub, so it just sent me back to the app url set in the GitHub OAuth app.

chanmathew commented 3 months ago

@j4w8n Yeah that's right, the metadata doesn't come back during the conversion.

As for the redirectTo, my understanding is that it only redirects after the authentication, so I just use that to redirect to a specific page within my app.

jonnylangefeld commented 3 months ago

I just came here because I ran into the same issue. It is true that if the user logs out and in again after a supabase.auth.linkIdentity the raw_user_meta_data is there, but it should be there even with just linkIdentity.

Any fix or workaround would be appreciated.

abeisleem commented 2 months ago

Same issue here. Would appreciate a workaround or a fix.