[GH-ISSUE #3766] Reddit doesn't return an email so new users are added to first registered user as accounts #18347

Closed
opened 2026-04-15 16:47:07 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @DieTL95 on GitHub (Aug 3, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3766

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

As per a reddit admin (link), Reddit doesn't expose users' emails, what is returned instead is the same UUID for all users it seems.

Current vs. Expected behavior

So instead of having multiple users, you have the first registered user, with their account name, etc, and every subsequent user is added as an additional "account" to that user, and if you by default return the name and image, it will return to them the details of that user, instead of their own.

What version of Better Auth are you using?

1.3.4

Provide environment information

Windows 10

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)


Additional context

It's easy to solve just by mapping profile to user and using the name for the email

const prisma = new PrismaClient();
export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql", // or "mysql", "postgresql", ...etc
  }),

  socialProviders: {
    reddit: {
      clientId: process.env.REDDIT_CLIENT as string,
      clientSecret: process.env.REDDIT_SECRET as string,
      scope: redditScopes,
      duration: "permanent",
      mapProfileToUser: (profile) => {
        return {
          email: profile.name,
          name: profile.name,
          id: profile.id,
          image: profile.icon_img || "",
          emailVerified: profile.has_verified_email,
        };
      },
    },
  },
});
Originally created by @DieTL95 on GitHub (Aug 3, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3766 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce As per a reddit admin ([link](https://www.reddit.com/r/redditdev/comments/e6i85y/reddit_api_oauth2_request_user_email_address/f9qzk96/)), Reddit doesn't expose users' emails, what is returned instead is the same UUID for all users it seems. ### Current vs. Expected behavior So instead of having multiple users, you have the first registered user, with their account name, etc, and every subsequent user is added as an additional "account" to that user, and if you by default return the name and image, it will return to them the details of that user, instead of their own. ### What version of Better Auth are you using? 1.3.4 ### Provide environment information ```bash Windows 10 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript ``` ### Additional context It's easy to solve just by mapping profile to user and using the name for the email ``` const prisma = new PrismaClient(); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", // or "mysql", "postgresql", ...etc }), socialProviders: { reddit: { clientId: process.env.REDDIT_CLIENT as string, clientSecret: process.env.REDDIT_SECRET as string, scope: redditScopes, duration: "permanent", mapProfileToUser: (profile) => { return { email: profile.name, name: profile.name, id: profile.id, image: profile.icon_img || "", emailVerified: profile.has_verified_email, }; }, }, }, }); ```
GiteaMirror added the locked label 2026-04-15 16:47:07 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 3, 2025):

This happens because Better Auth relies on the email field to uniquely identify users, but Reddit's OAuth API doesn't provide a unique email—sometimes not even a unique ID—so all users end up merged under the first account with the same "email" value ref.

Mapping profile.name to the email field works only if Reddit usernames are unique and never change, but it's safer to use profile.id (which is Reddit's unique user ID) to generate a fake email, like ${profile.id}@reddit.local. This pattern is the recommended workaround for other providers that don't return emails, such as Discord ref.

Example:

mapProfileToUser: (profile) => ({
  email: `${profile.id}@reddit.local`,
  name: profile.name,
  id: profile.id,
  image: profile.icon_img || "",
  emailVerified: false, // Reddit doesn't verify emails
}),

This ensures each Reddit user is mapped to a unique account in your system. Be aware that if Reddit ever changes how IDs are issued, or if you use a non-unique field, you could see collisions or impersonation issues.

If you want to prevent account merging from other social providers, you can also disable account linking in your Better Auth config ref.

Let me know if you want more details on handling other edge cases or custom user mapping!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3147194532 --> @dosubot[bot] commented on GitHub (Aug 3, 2025): <!-- Answer --> This happens because Better Auth relies on the email field to uniquely identify users, but Reddit's OAuth API doesn't provide a unique email—sometimes not even a unique ID—so all users end up merged under the first account with the same "email" value [ref](https://github.com/better-auth/better-auth/blob/987be984b4d840a409ca1e0d6098ee0f3303bcb6/packages/better-auth/src/plugins/generic-oauth/index.ts). Mapping `profile.name` to the email field works only if Reddit usernames are unique and never change, but it's safer to use `profile.id` (which is Reddit's unique user ID) to generate a fake email, like `${profile.id}@reddit.local`. This pattern is the recommended workaround for other providers that don't return emails, such as Discord [ref](https://github.com/better-auth/better-auth/issues/2059). Example: ```typescript mapProfileToUser: (profile) => ({ email: `${profile.id}@reddit.local`, name: profile.name, id: profile.id, image: profile.icon_img || "", emailVerified: false, // Reddit doesn't verify emails }), ``` This ensures each Reddit user is mapped to a unique account in your system. Be aware that if Reddit ever changes how IDs are issued, or if you use a non-unique field, you could see collisions or impersonation issues. If you want to prevent account merging from other social providers, you can also disable account linking in your Better Auth config [ref](https://github.com/better-auth/better-auth/issues/1745). Let me know if you want more details on handling other edge cases or custom user mapping! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/65dd2f0a-efdf-4cb2-a932-6838f2074e69?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3766)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18347