Custom values into `authClient.signIn.social()`?

Hey there 👋 What's the best way to manually set user values when signing a user in through an OAuth provider? For example, I may want to set a custom, default user image instead of using your social provider image, or I may want a custom name or username. Since I am using Next.js, intercepting the user with a layout function is pretty trivial, but maybe there is some Better-Auth way to do this through hooks or something similar?
Solution:
you can actually map the value here for example ``` socialProviders: { google: { clientId: "YOUR_GOOGLE_CLIENT_ID",...
Jump to solution
2 Replies
Solution
KiNFiSH
KiNFiSH•3w ago
you can actually map the value here for example
socialProviders: {
google: {
clientId: "YOUR_GOOGLE_CLIENT_ID",
clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
mapProfileToUser: (profile) => {
return {
// Override default image with your custom one
image: "https://your-domain.com/default-avatar.png",

// Customize the name format
name: `${profile.given_name} ${profile.family_name}`,

// Add any additional fields you want to set
username: profile.email.split('@')[0],

// You can still access the original profile data
// profile.picture, profile.name, etc.
};
}
}
}
socialProviders: {
google: {
clientId: "YOUR_GOOGLE_CLIENT_ID",
clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
mapProfileToUser: (profile) => {
return {
// Override default image with your custom one
image: "https://your-domain.com/default-avatar.png",

// Customize the name format
name: `${profile.given_name} ${profile.family_name}`,

// Add any additional fields you want to set
username: profile.email.split('@')[0],

// You can still access the original profile data
// profile.picture, profile.name, etc.
};
}
}
}
Json 👺
Json 👺OP•3w ago
Terrific, thanks!

Did you find this page helpful?