Generic oauth failing on missing email

Ouath providers that do not offer an email claim fail when using the generic oauth plugin with email_is_missing. Seeing how both Twitter and Tiktok allow for null emails, I would expect similar behavior in the generic oauth plugin as well. Or, alternatively, a way (a la Auth.js) to write and use custom providers. Moreover, mapProfileToUser has no affect on the above as this method is being invoked after the email check fails. One must use a custom getUserInfo method to get around this restriction. See here: https://github.com/better-auth/better-auth/blob/6a0898fa88d1a49163b711fdbfa05489e0301a2c/packages/better-auth/src/plugins/generic-oauth/index.ts#L606
2 Replies
thederezz
thederezz2w ago
Ran into the same problem, spent the last 2 days trying to figure it out and your comment helped me. Since in the code it's only checking if the email is there, you can literally put anything. In my case I just put the username.
getUserInfo: async (tokens) => {
const profile = await getUserProfile(tokens.accessToken);

return {
id: profile.id,
name: profile.name,
email: profile.username,
image: profile.threads_profile_picture_url,
emailVerified: true,
createdAt: new Date(),
updatedAt: new Date(),
};
}
getUserInfo: async (tokens) => {
const profile = await getUserProfile(tokens.accessToken);

return {
id: profile.id,
name: profile.name,
email: profile.username,
image: profile.threads_profile_picture_url,
emailVerified: true,
createdAt: new Date(),
updatedAt: new Date(),
};
}
shu-sin
shu-sinOP2w ago
Yes but I have proposed this in another place and haven't yet received a response. This is our current approach too however I am not sure if this has a knock-on effect in other areas of auth where the email is expected to be resolvable (invite emails, etc) I am looking now into options using the username plugin and/or remapping user.email attribute to something like a uniqueId that could be an email or username I do still think email should be nullable personally

Did you find this page helpful?