[GH-ISSUE #4913] Anonymous user plugin failing due to Stripe plugin #18740

Closed
opened 2026-04-15 17:22:02 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @focux on GitHub (Sep 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4913

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When the anonymous user plugin is enabled, the signup flow attempts to create a Stripe customer while the user is still anonymous. Stripe rejects the request due to an invalid email format generated for the temporary anonymous user, causing customer creation to fail.

Error
Error: Invalid email address: temp-tzhd5yviw70h7avlkdyutu6xno2kqisi@http://localhost:3000

Steps to Reproduce

  1. Enable anonymous and stripe plugin.
  2. Start session as an anonymous user.

Current vs. Expected behavior

I expect the customer no to be created for anonymous users

What version of Better Auth are you using?

1.3.7

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Fri Sep 19 19:14:26 PDT 2025; root:xnu-12377.40.77.505.1~4/RELEASE_ARM64_T6000",
    "release": "25.1.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Max",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.11 GB"
  },
  "node": {
    "version": "v22.16.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "postgres",
      "version": "^3.4.7"
    },
    {
      "name": "drizzle",
      "version": "1.0.0-beta.1-84d9a79"
    }
  ],
  "betterAuth": {
    "version": "^1.3.7",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
 plugins: [
    anonymousClient(),
    stripeClient({
      subscription: true,
    }),
  ],
});

Additional context

No response

Originally created by @focux on GitHub (Sep 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4913 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When the anonymous user plugin is enabled, the signup flow attempts to create a Stripe customer while the user is still anonymous. Stripe rejects the request due to an invalid email format generated for the temporary anonymous user, causing customer creation to fail. ``` Error Error: Invalid email address: temp-tzhd5yviw70h7avlkdyutu6xno2kqisi@http://localhost:3000 ``` ## Steps to Reproduce 1. Enable anonymous and stripe plugin. 2. Start session as an anonymous user. ### Current vs. Expected behavior I expect the customer no to be created for anonymous users ### What version of Better Auth are you using? 1.3.7 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Fri Sep 19 19:14:26 PDT 2025; root:xnu-12377.40.77.505.1~4/RELEASE_ARM64_T6000", "release": "25.1.0", "cpuCount": 10, "cpuModel": "Apple M1 Max", "totalMemory": "32.00 GB", "freeMemory": "0.11 GB" }, "node": { "version": "v22.16.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": null, "databases": [ { "name": "postgres", "version": "^3.4.7" }, { "name": "drizzle", "version": "1.0.0-beta.1-84d9a79" } ], "betterAuth": { "version": "^1.3.7", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [ anonymousClient(), stripeClient({ subscription: true, }), ], }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 17:22:02 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 25, 2025):

This is a valid GitHub issue. The Stripe plugin currently does not check if a user is anonymous before attempting to create a Stripe customer, which leads to failures when the anonymous plugin generates temporary emails that Stripe rejects as invalid. The anonymous plugin reliably marks users with isAnonymous: true, but the Stripe plugin does not use this flag to skip customer creation for anonymous users source.

Workaround:
You can disable automatic customer creation by setting createCustomerOnSignUp: false in your Stripe plugin config, then manually create Stripe customers only for registered (non-anonymous) users. Alternatively, patch the Stripe plugin's user creation hook to add a guard like:

async after(user, ctx) {
  if (ctx && options.createCustomerOnSignUp && !user.isAnonymous) {
    // ...create Stripe customer logic
  }
}

This will prevent Stripe customer creation for anonymous users and avoid the invalid email error source.

Let me know if you need a more detailed code example or help with a custom hook!

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:3336030205 --> @dosubot[bot] commented on GitHub (Sep 25, 2025): <!-- Answer --> This is a valid GitHub issue. The Stripe plugin currently does not check if a user is anonymous before attempting to create a Stripe customer, which leads to failures when the anonymous plugin generates temporary emails that Stripe rejects as invalid. The anonymous plugin reliably marks users with `isAnonymous: true`, but the Stripe plugin does not use this flag to skip customer creation for anonymous users [source](https://github.com/better-auth/better-auth/blob/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b/packages/stripe/src/index.ts). **Workaround:** You can disable automatic customer creation by setting `createCustomerOnSignUp: false` in your Stripe plugin config, then manually create Stripe customers only for registered (non-anonymous) users. Alternatively, patch the Stripe plugin's user creation hook to add a guard like: ```typescript async after(user, ctx) { if (ctx && options.createCustomerOnSignUp && !user.isAnonymous) { // ...create Stripe customer logic } } ``` This will prevent Stripe customer creation for anonymous users and avoid the invalid email error [source](https://github.com/better-auth/better-auth/blob/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b/packages/better-auth/src/plugins/anonymous/index.ts). Let me know if you need a more detailed code example or help with a custom hook! <!-- 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/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/191f2d76-cf9a-49cf-a906-975b794ea203?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/4913)
Author
Owner

@AntonVishal commented on GitHub (Sep 28, 2025):

Hey @focux my use case is that I wanted to allow anonymous users to purchase in my marketplace like a one time thing, they dont have to authenticate. So what would you recommend, This PR contradicts that right?

<!-- gh-comment-id:3343942831 --> @AntonVishal commented on GitHub (Sep 28, 2025): Hey @focux my use case is that I wanted to allow anonymous users to purchase in my marketplace like a one time thing, they dont have to authenticate. So what would you recommend, This PR contradicts that right?
Author
Owner

@Bekacru commented on GitHub (Sep 30, 2025):

The user should still be able to checkout with stripe even if they are anonymous. You can change the emailDomainName in your anonymous plugin config to fix this

<!-- gh-comment-id:3350145087 --> @Bekacru commented on GitHub (Sep 30, 2025): The user should still be able to checkout with stripe even if they are anonymous. You can change the `emailDomainName` in your anonymous plugin config to fix this
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18740