supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

Full Name not stored in Database when Using Apple Sign-In in React Native #899

Open VictorienDruon opened 6 months ago

VictorienDruon commented 6 months ago

Description

When using Apple's native sign-in with React Native and the signInWithIdToken method, the raw_user_meta_data in the auth.users table doesn't include the newly created user's full name. Even though AppleAuthentication.signInAsync provides both the email and full name, only the email is stored in the database.

Code:

const credential = await AppleAuthentication.signInAsync({
  requestedScopes: [
    AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
    AppleAuthentication.AppleAuthenticationScope.EMAIL,
  ],
});

console.log(credential);

if (credential.identityToken) {
  const { error } = await supabase.auth.signInWithIdToken({
      provider: "apple",
      token: credential.identityToken,
  });
}

Console log:

{
  authorizationCode: "**********",
  email: "**********",
  fullName: {
  familyName: "Druon",
  givenName: "Victorien",
  middleName: null,
  namePrefix: null,
  nameSuffix: null,
  nickname: null,
  },
  identityToken: "**********",
  realUserStatus: 2,
  state: null,
  user: "**********",
}

Supabase auth.users.raw_user_meta_data:

{
  "iss": "https://appleid.apple.com",
  "sub": "**********",
  "email": "**********",
  "provider_id": "**********",
  "custom_claims": {
    "auth_time": 1698918001
  },
  "email_verified": true
}

To Reproduce

Follow the Supabase login with Apple with Expo React Native documentation: https://supabase.com/docs/guides/auth/social-login/auth-apple?platform=react-native

Expected behavior

The user's full name should be added to raw_user_meta_data.

System information

"dependencies": {
  ...
  "@supabase/supabase-js": "^2.31.0",
  "expo": "~49.0.5",
  "expo-apple-authentication": "~6.1.0",
  "expo-auth-session": "~5.0.2",
  "expo-router": "2.0.0",
  "react": "18.2.0",
  "react-native": "0.72.6",
  "supabase": "^1.82.2",
  ...
},

Additional context

aalmho commented 6 months ago

I have the same problem with auth.users not including the name of the user upon sign up. However by maintaining users in a public tabel like proposed by supabase: https://supabase.com/docs/guides/auth/managing-user-data and creating a trigger to create a profile, you can do a work around to upsert or update the profiles table when signup is successful like:

await supabase.from("profiles").upsert({id: user?.id, first_name: credential.fullName?.givenName, last_name: credential.fullName?.familyName}).eq("id", user?.id);

VictorienDruon commented 6 months ago

Yeah, that would work, but it would be better if we didn't have to do this workaround. Because of that, we can't use supabase.auth.getUser() and have up-to-date user information. I wish signInWithIdToken would handle this automatically or at least allow us to pass additional user metadata, similar to how it works with supabase.auth.signUp()

Schotsl commented 5 months ago

I'm running into the same issue. While using the metadata from the JavaScript call does work. It adds a unneeded step to the signup process.

ryonwhyte commented 5 months ago

Ran into the same issue here. Apple is the last I am integrating of a few social networks. Now, I'll need to write some sort of workaround into my login process.

vbylen commented 1 month ago

can confirm this is still an issue