Support image field in linking account #1064

Closed
opened 2026-03-13 08:20:57 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @coderrshyam on GitHub (Apr 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

When this feild or colums enabled and user already linked their account we can change image using socials by which it links their account.

Describe the solution you'd like

Add image column in account linking

Describe alternatives you've considered

There is no alternative

Additional context

No response

Originally created by @coderrshyam on GitHub (Apr 16, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When this feild or colums enabled and user already linked their account we can change image using `socials` by which it links their account. ### Describe the solution you'd like Add image column in account linking ### Describe alternatives you've considered There is no alternative ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 08:20:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 20, 2025):

Hi, @coderrshyam. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Proposal to add an image field to the account linking process.
  • Feature would allow users to update profile images via social media accounts.
  • Mentioned as beneficial for GitHub with no alternative solutions available.
  • No further comments or developments since the issue was opened.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jul 20, 2025): Hi, @coderrshyam. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Proposal to add an image field to the account linking process. - Feature would allow users to update profile images via social media accounts. - Mentioned as beneficial for GitHub with no alternative solutions available. - No further comments or developments since the issue was opened. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@coderrshyam commented on GitHub (Jul 20, 2025):

Ya, I wants this feature

@coderrshyam commented on GitHub (Jul 20, 2025): Ya, I wants this feature
Author
Owner

@Inzendis commented on GitHub (Sep 17, 2025):

Hey I was looking for this, but you can update the db, the account img url when you mapProfileToUser just make it async and await db ....

@Inzendis commented on GitHub (Sep 17, 2025): Hey I was looking for this, but you can update the db, the account img url when you mapProfileToUser just make it async and await db ....
Author
Owner

@coderrshyam commented on GitHub (Sep 17, 2025):

Hey I was looking for this, but you can update the db, the account img url when you mapProfileToUser just make it async and await db ....

Can you provide code example

@coderrshyam commented on GitHub (Sep 17, 2025): > Hey I was looking for this, but you can update the db, the account img url when you mapProfileToUser just make it async and await db .... Can you provide code example
Author
Owner

@Inzendis commented on GitHub (Sep 17, 2025):

Not sure if its the most elegant solution, but it works. I have it so I can link both google account and discord account. If I login with discord, I update the img url from user in the db. Using almost the default schema from betterAuth.

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  user: {
    additionalFields: {
      accountLoyaltyStatus: {
        type: "string",
        default: "standard",
        input: false,
      },
    },
  },
  rateLimit: {
    enabled: true,
    window: 7,
    max: 100,
    storage: "memory",
    modelName: "rateLimit",
  },
  account: {
    encryptOAuthTokens: true,
    accountLinking: {
      enabled: true,
      allowDifferentEmails: true,
      updateUserInfoOnLink: true,
    },
  },
  baseURL: process.env.BETTER_AUTH_URL as string,
  secret: process.env.BETTER_AUTH_SECRET as string,
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
      redirectURI: `${process.env.BETTER_AUTH_URL}/api/auth/callback/google`,
      mapProfileToUser: (profile) => {
        return {
          name: profile.name,
          email: profile.email,
          image: profile.picture,
          accountLoyaltyStatus: "standard",
        };
      },
      accessType: "offline",
      prompt: "select_account consent",
    },
    discord: {
      clientId: process.env.DISCORD_CLIENT_ID as string,
      clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
      redirectURI: `${process.env.BETTER_AUTH_URL}/api/auth/callback/discord`,
      mapProfileToUser: async (profile) => {
        const img = profile.avatar
          ? `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.gif`
          : undefined;

        const accountInDB = await db
          .select()
          .from(account)
          .where(eq(account.accountId, profile.id));

        if (accountInDB.length > 0) {
          await db
            .update(user)
            .set({ image: img })
            .where(eq(user.id, accountInDB[0]?.userId));
        }

        return {
          name: profile.username,
          email: profile.email,
          image: img,
          accountLoyaltyStatus: "standard",
        };
      },
    },
  },

  session: { expiresIn: 30 * 24 * 60 * 60 }, // 30 days
});
@Inzendis commented on GitHub (Sep 17, 2025): Not sure if its the most elegant solution, but it works. I have it so I can link both google account and discord account. If I login with discord, I update the img url from user in the db. Using almost the default schema from betterAuth. ``` export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), user: { additionalFields: { accountLoyaltyStatus: { type: "string", default: "standard", input: false, }, }, }, rateLimit: { enabled: true, window: 7, max: 100, storage: "memory", modelName: "rateLimit", }, account: { encryptOAuthTokens: true, accountLinking: { enabled: true, allowDifferentEmails: true, updateUserInfoOnLink: true, }, }, baseURL: process.env.BETTER_AUTH_URL as string, secret: process.env.BETTER_AUTH_SECRET as string, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, redirectURI: `${process.env.BETTER_AUTH_URL}/api/auth/callback/google`, mapProfileToUser: (profile) => { return { name: profile.name, email: profile.email, image: profile.picture, accountLoyaltyStatus: "standard", }; }, accessType: "offline", prompt: "select_account consent", }, discord: { clientId: process.env.DISCORD_CLIENT_ID as string, clientSecret: process.env.DISCORD_CLIENT_SECRET as string, redirectURI: `${process.env.BETTER_AUTH_URL}/api/auth/callback/discord`, mapProfileToUser: async (profile) => { const img = profile.avatar ? `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.gif` : undefined; const accountInDB = await db .select() .from(account) .where(eq(account.accountId, profile.id)); if (accountInDB.length > 0) { await db .update(user) .set({ image: img }) .where(eq(user.id, accountInDB[0]?.userId)); } return { name: profile.username, email: profile.email, image: img, accountLoyaltyStatus: "standard", }; }, }, }, session: { expiresIn: 30 * 24 * 60 * 60 }, // 30 days }); ```
Author
Owner

@coderrshyam commented on GitHub (Sep 17, 2025):

@Inzendis This is really useful during login. But how can we extend it to support importing a profile picture directly?

For example, suppose we have a button labeled “Import profile picture from Google.” How would we implement that?

To enable this functionality, each account schema should include an image column to store the profile picture.

By the way, your approach is very solid—great work!

@coderrshyam commented on GitHub (Sep 17, 2025): @Inzendis This is really useful during login. But how can we extend it to support importing a profile picture directly? For example, suppose we have a button labeled **“Import profile picture from Google.”** How would we implement that? To enable this functionality, each `account` schema should include an `image` column to store the profile picture. By the way, your approach is very solid—great work!
Author
Owner

@himself65 commented on GitHub (Sep 25, 2025):

I think what Inzendis is great. Right now, we have no plan to add this field as built-in. You can have such a workaround to make that happen

@himself65 commented on GitHub (Sep 25, 2025): I think what Inzendis is great. Right now, we have no plan to add this field as built-in. You can have such a workaround to make that happen
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1064