social signUp flow

I want to enable my users to sign up with Apple. I have additional required fields on the user model:
user: {
additionalFields: {
surname: {
type: "string",
required: true,
},
type: {
type: "string",
required: true,
},
},
},
user: {
additionalFields: {
surname: {
type: "string",
required: true,
},
type: {
type: "string",
required: true,
},
},
},
Using email signUp flow I can add those fields as 1st argument to the signUp function: authClient.signUp.email(registerFormData, { ... How can I do the same using authClient.signIn.social({provider: 'apple' ...
2 Replies
KiNFiSH
KiNFiSH6d ago
if the data actually coming from the apple provider - you can us mapUserToProfile -
export const auth = betterAuth({
// ... other config
socialProviders: {
apple: {
enabled: true,
clientId: process.env.APPLE_CLIENT_ID!,
clientSecret: process.env.APPLE_CLIENT_SECRET!,
mapProfileToUser: async (profile) => {
return {
// Basic fields from Apple
name: profile.name?.firstName || '',
email: profile.email,
emailVerified: true,

// Your additional required fields
surname: profile.name?.lastName || '', // If Apple provides lastName
type: 'default', // Set a default value

};
}
}
}
});
export const auth = betterAuth({
// ... other config
socialProviders: {
apple: {
enabled: true,
clientId: process.env.APPLE_CLIENT_ID!,
clientSecret: process.env.APPLE_CLIENT_SECRET!,
mapProfileToUser: async (profile) => {
return {
// Basic fields from Apple
name: profile.name?.firstName || '',
email: profile.email,
emailVerified: true,

// Your additional required fields
surname: profile.name?.lastName || '', // If Apple provides lastName
type: 'default', // Set a default value

};
}
}
}
});
Eddie1O
Eddie1OOP6d ago
Thank You! Apple is sending this data (firstName, lastName) somewhat differently - the profile has some tokens, dates and email, but no names. I can find the data in the network tab after betterAuth throws an error at me (surname not provided). But I'm not sure how to access it

Did you find this page helpful?