Doppio
Doppio
BABetter Auth
Created by Doppio on 4/28/2025 in #help
Getting users' organization details in JWT token
Hi! Is there a way to get the users' organization details (such as organizations the user is a member for or the currently selected one) in the JWT token claims, using the JWT plugins? Thanks!
2 replies
BABetter Auth
Created by Doppio on 4/13/2025 in #bug-reports
[breaking] mapProfileToUser gets called twice when logging in via ID Tokens, breaking authentication
Hi, mapProfileToUser seems to be getting called twice when logging in via Social Provider ID Tokens. By putting a logger.info(); in the provider mapProfileToUser, you can see that it logs two values, the first being the actual response from the provider, the second one being the Better Auth user object. This leads to the UNABLE_TO_CREATE_USER error due to the fact that the second response does not contain provider-native arguments such as profile.given_name
2 replies
BABetter Auth
Created by Doppio on 3/3/2025 in #bug-reports
mapProfileToUser doesn't work when using ID token authentication
Hi, great work on Better Auth! When using ID tokens to log in into a sign in provider (e.g. Google with ID token and access token, as aspecified here ), mapProfileToUser parameters are not passed to the user object, thus not being stored in the database neither. I've set up additionalAttributes on the user object. If those are required, Prisma complains about those parameters not being specified while creating the user object. If those are not required they are just left as null Backend auth.ts
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "mysql"
}),
plugins: [
openAPI()
],
user: {
additionalFields: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
}
},
socialProviders: {
google: {
clientId: "...",
clientSecret: "...",

mapProfileToUser: (profile) => {
return {
firstName: profile.given_name,
lastName: profile.family_name,
};
},
},
},
})
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "mysql"
}),
plugins: [
openAPI()
],
user: {
additionalFields: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
}
},
socialProviders: {
google: {
clientId: "...",
clientSecret: "...",

mapProfileToUser: (profile) => {
return {
firstName: profile.given_name,
lastName: profile.family_name,
};
},
},
},
})
Frontend code:
const data = await authClient.signIn.social({
provider: "google",
idToken: {
token: "...",
accessToken: "..."
}
})
const data = await authClient.signIn.social({
provider: "google",
idToken: {
token: "...",
accessToken: "..."
}
})
Using Better Auth v.1.2.1. Any ideas? Thank you!
4 replies