mapProfileToUser doesnt work

I have a problem: mapProfileToUser doesn’t work when I want to grab and save my user’s Discord ID as identifier in the session.

When I print the profile, it contains the id (which is the Discord ID) property. However, when I print my session user, there is no identifier property.

auth.ts

export const auth = betterAuth({
    database: createPool({
        host: x,
        user: x,
        password: x,
        database: x,
    }),
    socialProviders: {
        discord: {
            clientId: process.env.DISCORD_CLIENT_ID as string,
            clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
            mapProfileToUser: (profile) => {
                console.log(profile)
                return {
                    identifier: profile.id
                };
            }
        }
    },
    secret: process.env.BETTER_AUTH_SECRET as string,
    [...]
Was this page helpful?