supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

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

Open VictorienDruon opened this issue 2 years ago • 17 comments

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

  • Apple only returns the requested information on the very first authentication. The log above is what you get for the first auth.
  • There is a similar issue in supabase-flutter: https://github.com/supabase/supabase-flutter/issues/545

VictorienDruon avatar Nov 02 '23 10:11 VictorienDruon

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);

aalmho avatar Nov 07 '23 21:11 aalmho

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()

VictorienDruon avatar Nov 08 '23 15:11 VictorienDruon

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.

Schotsl avatar Nov 30 '23 16:11 Schotsl

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.

ryonwhyte avatar Dec 17 '23 05:12 ryonwhyte

can confirm this is still an issue

cloudorbush avatar Apr 14 '24 11:04 cloudorbush

+1

guilhermefc avatar Jun 04 '24 01:06 guilhermefc

+1

stephanrueschenbaum avatar Jul 08 '24 15:07 stephanrueschenbaum

I'm also getting this issue

andyngdz avatar Jul 15 '24 08:07 andyngdz

any update ??

TuanTran-Tsk avatar Jul 30 '24 02:07 TuanTran-Tsk

hey everyone, as a workaround, you can call supabase.auth.updateUser to update the raw_user_meta_data to include the full_name of the user

kangmingtay avatar Jul 31 '24 19:07 kangmingtay

I'm unable to retrieve it even when I look into the credential object. It's always null even though I removed the Expo app from the "Sign in with Apple" list.

FezVrasta avatar Aug 19 '24 06:08 FezVrasta

Same with Flutter

sbpro86 avatar Sep 17 '24 23:09 sbpro86

I'm unable to retrieve it even when I look into the credential object. It's always null even though I removed the Expo app from the "Sign in with Apple" list.

It's impossible to get it again. You'd need to delete your Apple App ID and recreate an App ID, service ID, certificates, etc.

azizsafudin avatar Sep 28 '24 06:09 azizsafudin