[GH-ISSUE #950] Feat: Profile Hooks #8516

Closed
opened 2026-04-13 03:36:30 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @Blade67 on GitHub (Dec 19, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/950

Is this suited for github?

  • Yes, this is suited for github

It currently seems impossible to update User values based on their linked social provider Profiles, making it hard to sync data between social providers and User tables.

Describe the solution you'd like

I would suggest Profile hooks that are triggered on each sign-in and potentially sign-out.

socialProviders: {
    discord: {
        clientId: env.DISCORD_CLIENT_ID || '',
        clientSecret: env.DISCORD_CLIENT_SECRET || '',
        redirectUri:
                '<DiscordOAuthURI>',
        scope: ['identify', 'email'],
        prompt: 'consent',
        mapProfileToUser: (profile) => {
            return {
                image: profile.image_url
            };
        },
        signIn: (user, profile) => {
            return {
                image: user.image !== profile.image_url && profile.image_url // example usage
            }
        },
        signOut: (user, profile) => {    // optional
        },
    }
}

In the example above I provide both, the current User as it is saved in the database, and the profile received from the social provider - in this case Discord. This allows for more flexibility.

Describe alternatives you've considered

One consideration would to be to update the databaseHooks session hooks to account for sign-in/out and pass both, Profile and User there too. However this seems a bit too loaded and out of scope for those.

Additional context

No response

Originally created by @Blade67 on GitHub (Dec 19, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/950 ### Is this suited for github? - [X] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. It currently seems impossible to update User values based on their linked social provider Profiles, making it hard to sync data between social providers and User tables. ### Describe the solution you'd like I would suggest Profile hooks that are triggered on each sign-in and potentially sign-out. ```ts socialProviders: { discord: { clientId: env.DISCORD_CLIENT_ID || '', clientSecret: env.DISCORD_CLIENT_SECRET || '', redirectUri: '<DiscordOAuthURI>', scope: ['identify', 'email'], prompt: 'consent', mapProfileToUser: (profile) => { return { image: profile.image_url }; }, signIn: (user, profile) => { return { image: user.image !== profile.image_url && profile.image_url // example usage } }, signOut: (user, profile) => { // optional }, } } ``` In the example above I provide both, the current User as it is saved in the database, and the profile received from the social provider - in this case Discord. This allows for more flexibility. ### Describe alternatives you've considered One consideration would to be to update the `databaseHooks` session hooks to account for sign-in/out and pass both, Profile and User there too. However this seems a bit too loaded and out of scope for those. ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 03:36:30 -05:00
Author
Owner

@Q16solver commented on GitHub (Jan 17, 2025):

I need something similar to this, but on a more generic level. I want to have a sign-in hook that lets me update values to the user table which currently doesn’t seem possible

<!-- gh-comment-id:2597355202 --> @Q16solver commented on GitHub (Jan 17, 2025): I need something similar to this, but on a more generic level. I want to have a sign-in hook that lets me update values to the user table which currently doesn’t seem possible
Author
Owner

@Blade67 commented on GitHub (Jan 17, 2025):

Mutating schema seems a bit tricky. Having some kind of arbitrary data key would likely allow that as well. ie. in PostGres you can have values be arbitrary JSON data. This could be used for your use case, @Q16solver.
This proposal would mostly allow to modify users upon sign-in/out to begin with, opening a lot of opportunities.

<!-- gh-comment-id:2599142840 --> @Blade67 commented on GitHub (Jan 17, 2025): Mutating schema seems a bit tricky. Having some kind of arbitrary data key would likely allow that as well. ie. in PostGres you can have values be arbitrary JSON data. This could be used for your use case, @Q16solver. This proposal would mostly allow to modify users upon sign-in/out to begin with, opening a lot of opportunities.
Author
Owner

@Q16solver commented on GitHub (Jan 18, 2025):

Woops, just realised the wording there I have is confusing. Extending the core schema is already supported. I meant that I wanted to update values in the schema in the signin hook e.g db.update(lastLogin)

<!-- gh-comment-id:2599431423 --> @Q16solver commented on GitHub (Jan 18, 2025): Woops, just realised the wording there I have is confusing. Extending the core schema is already supported. I meant that I wanted to update values in the schema in the signin hook e.g db.update(lastLogin)
Author
Owner

@arxk commented on GitHub (Jan 20, 2025):

Love to have this feature! compatible with Generic OAuth too!

<!-- gh-comment-id:2601425116 --> @arxk commented on GitHub (Jan 20, 2025): Love to have this feature! compatible with Generic OAuth too!
Author
Owner

@prokopsimek commented on GitHub (Feb 18, 2025):

I need the same to whitelist e-mail addresses for sign-up/sign-in for social providers too.

<!-- gh-comment-id:2665283214 --> @prokopsimek commented on GitHub (Feb 18, 2025): I need the same to whitelist e-mail addresses for sign-up/sign-in for social providers too.
Author
Owner

@mfragale commented on GitHub (Mar 31, 2025):

True, it does seem impossible to update User values based on their linked social provider Profiles, which is weird because if a user signs up directly using an external social provider their info is imported properly, including their profile image.

<!-- gh-comment-id:2767300906 --> @mfragale commented on GitHub (Mar 31, 2025): True, it does seem impossible to update User values based on their linked social provider Profiles, which is weird because if a user signs up directly using an external social provider their info is imported properly, including their profile image.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8516