[BUG] Unknown argument eq on Prisma adapter. #1294

Closed
opened 2026-03-13 08:31:41 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Konixy on GitHub (Jun 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

call

authClient.subscription.upgrade({ subscriptionId: "whatever" })

and this will throw the following 500 error to the client:

# SERVER_ERROR:  PrismaClientValidationError: 
Invalid `prisma.subscription.findFirst()` invocation:

{
  where: {
    OR: [
      {
        id: {
          eq: "whatever"
        }
      },
      {
        stripeSubscriptionId: {
          eq: "whatever"
        }
      }
    ]
  },
  select: undefined
}

Unknown argument `eq`. Did you mean `in`? Available options are marked with ?.
    at kn (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:29:1363)
    at Zn.handleRequestError (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:7102)
    at Zn.handleAndLogRequestError (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:6784)
    at Zn.request (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:6491)
    at async l (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:130:9778)
    at async Object.findOne (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/adapters/prisma-adapter/index.mjs:107:16)
    at async Object.findOne (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/shared/better-auth.Dpv9J4ny.mjs:523:19)
    at async eval (/Users/anatole/Desktop/Code/web/better-auth/packages/stripe/dist/index.mjs:426:64)
    at async internalHandler (file:///Users/anatole/Desktop/Code/web/better-auth/node_modules/better-call/dist/index.js:571:22)
    at async api.<computed> (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/api/index.mjs:561:22) {
  clientVersion: '6.8.2'
}

Current vs. Expected behavior

Expected these lines to be like these lines

What version of Better Auth are you using?

1.2.9-beta.8

Provide environment information

- OS: MacOS
- Browser: Arc (chromium)

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

Package, Backend

Auth config (if applicable)

export const stripeClient = new Stripe(STRIPE_SECRET_KEY);

export const auth = betterAuth({
	plugins: [
		stripe({
			stripeClient,
			stripeWebhookSecret: STRIPE_WEBHOOK_SECRET,
			createCustomerOnSignUp: true,
			subscription: {
				enabled: true,
				organization: {
					enabled: true
				},
				plans: [
					{
						name: 'solo',
						priceId: STRIPE_SOLO_PRICE_ID,
						annualDiscountPriceId: STRIPE_SOLO_YEARLY_PRICE_ID,
						freeTrial: {
							days: 30,
							// Function that I created in another PR
							async isEligible({ user }) {
								const fullUser = await prisma.user.findUnique({
									where: { id: user.id },
									select: { hasUsedFreeTrial: true }
								});

								return !fullUser?.hasUsedFreeTrial;
							},
							async onTrialStart(subscription) {
								const user = await prisma.user.findFirst({
									where: { stripeCustomerId: subscription.stripeCustomerId }
								});

								if (user) {
									await prisma.user.update({
										where: { id: user.id },
										data: {
											hasUsedFreeTrial: true,
											freeTrialUsedAt: new Date()
										}
									});
								}

								await sendTrialEmail('start', subscription);
							},
							async onTrialEnd({ subscription }) {
								await sendTrialEmail('end', subscription);
							},
							async onTrialExpired(subscription) {
								await sendTrialEmail('expired', subscription);
							}
						},
						limits: {
							teams: 0,
							members: 0
						}
					},
					{
						name: 'team',
						priceId: STRIPE_TEAM_PRICE_ID,
						annualDiscountPriceId: STRIPE_TEAM_YEARLY_PRICE_ID,
						limits: {
							teams: 1,
							members: 5
						}
					},
					{
						name: 'teamPlus',
						priceId: STRIPE_TEAM_PLUS_PRICE_ID,
						annualDiscountPriceId: STRIPE_TEAM_PLUS_YEARLY_PRICE_ID,
						limits: {
							teams: 10,
							members: 50
						}
					}
				],
				requireEmailVerification: true,
				getCheckoutSessionParams() {
					return {
						params: {
							payment_method_collection: 'if_required'
						}
					};
				}
			}
		})
	],
	database: prismaAdapter(prisma, {
		provider: 'mongodb'
	}),
	emailAndPassword: {
		enabled: true,
		async sendResetPassword(data) {
			await sendResetPasswordEmail(data);
		}
	},
	user: {
		additionalFields: {
			currency: {
				type: Object.values(Currency),
				required: false,
				defaultValue: 'DEFAULT'
			},
			locale: {
				type: Object.values(Locale),
				required: true,
				defaultValue: 'en'
			},
			imageId: {
				type: 'string',
				required: false
			},
			statusOrder: {
				type: 'string[]',
				required: false,
				defaultValue: []
			}
		}
	},
	databaseHooks: {
		user: {
			create: {
				async before(user, context) {
					let locale = 'en';

					if (
						context?.body.locale &&
						typeof context.body.locale === 'string' &&
						Object.values(Locale).includes(context.body.locale)
					) {
						locale = context.body.locale;
					}

					return { data: { ...user, locale } };
				},
				async after(user) {
					await prisma.status.createMany({
						data: defaultStatus[(user as User).locale || 'en'].map((status) => ({
							...status,
							id: createId(),
							userId: user.id
						}))
					});
				}
			}
		}
	}
});

Additional context

Created #2874 that fixes the issue.

Originally created by @Konixy on GitHub (Jun 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce call ```ts authClient.subscription.upgrade({ subscriptionId: "whatever" }) ``` and this will throw the following 500 error to the client: ``` # SERVER_ERROR: PrismaClientValidationError: Invalid `prisma.subscription.findFirst()` invocation: { where: { OR: [ { id: { eq: "whatever" } }, { stripeSubscriptionId: { eq: "whatever" } } ] }, select: undefined } Unknown argument `eq`. Did you mean `in`? Available options are marked with ?. at kn (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:29:1363) at Zn.handleRequestError (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:7102) at Zn.handleAndLogRequestError (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:6784) at Zn.request (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:121:6491) at async l (/Users/anatole/Desktop/Code/web/djpilot/node_modules/@prisma/client/runtime/library.js:130:9778) at async Object.findOne (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/adapters/prisma-adapter/index.mjs:107:16) at async Object.findOne (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/shared/better-auth.Dpv9J4ny.mjs:523:19) at async eval (/Users/anatole/Desktop/Code/web/better-auth/packages/stripe/dist/index.mjs:426:64) at async internalHandler (file:///Users/anatole/Desktop/Code/web/better-auth/node_modules/better-call/dist/index.js:571:22) at async api.<computed> (/Users/anatole/Desktop/Code/web/better-auth/packages/better-auth/dist/api/index.mjs:561:22) { clientVersion: '6.8.2' } ``` ### Current vs. Expected behavior Expected [these lines](https://github.com/better-auth/better-auth/blob/1608444afc4477a66e124f82b1dea12e771ebf73/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L149-L151) to be like [these lines](https://github.com/better-auth/better-auth/blob/1608444afc4477a66e124f82b1dea12e771ebf73/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L138-L145) ### What version of Better Auth are you using? 1.2.9-beta.8 ### Provide environment information ```bash - OS: MacOS - Browser: Arc (chromium) ``` ### Which area(s) are affected? (Select all that apply) Package, Backend ### Auth config (if applicable) ```typescript export const stripeClient = new Stripe(STRIPE_SECRET_KEY); export const auth = betterAuth({ plugins: [ stripe({ stripeClient, stripeWebhookSecret: STRIPE_WEBHOOK_SECRET, createCustomerOnSignUp: true, subscription: { enabled: true, organization: { enabled: true }, plans: [ { name: 'solo', priceId: STRIPE_SOLO_PRICE_ID, annualDiscountPriceId: STRIPE_SOLO_YEARLY_PRICE_ID, freeTrial: { days: 30, // Function that I created in another PR async isEligible({ user }) { const fullUser = await prisma.user.findUnique({ where: { id: user.id }, select: { hasUsedFreeTrial: true } }); return !fullUser?.hasUsedFreeTrial; }, async onTrialStart(subscription) { const user = await prisma.user.findFirst({ where: { stripeCustomerId: subscription.stripeCustomerId } }); if (user) { await prisma.user.update({ where: { id: user.id }, data: { hasUsedFreeTrial: true, freeTrialUsedAt: new Date() } }); } await sendTrialEmail('start', subscription); }, async onTrialEnd({ subscription }) { await sendTrialEmail('end', subscription); }, async onTrialExpired(subscription) { await sendTrialEmail('expired', subscription); } }, limits: { teams: 0, members: 0 } }, { name: 'team', priceId: STRIPE_TEAM_PRICE_ID, annualDiscountPriceId: STRIPE_TEAM_YEARLY_PRICE_ID, limits: { teams: 1, members: 5 } }, { name: 'teamPlus', priceId: STRIPE_TEAM_PLUS_PRICE_ID, annualDiscountPriceId: STRIPE_TEAM_PLUS_YEARLY_PRICE_ID, limits: { teams: 10, members: 50 } } ], requireEmailVerification: true, getCheckoutSessionParams() { return { params: { payment_method_collection: 'if_required' } }; } } }) ], database: prismaAdapter(prisma, { provider: 'mongodb' }), emailAndPassword: { enabled: true, async sendResetPassword(data) { await sendResetPasswordEmail(data); } }, user: { additionalFields: { currency: { type: Object.values(Currency), required: false, defaultValue: 'DEFAULT' }, locale: { type: Object.values(Locale), required: true, defaultValue: 'en' }, imageId: { type: 'string', required: false }, statusOrder: { type: 'string[]', required: false, defaultValue: [] } } }, databaseHooks: { user: { create: { async before(user, context) { let locale = 'en'; if ( context?.body.locale && typeof context.body.locale === 'string' && Object.values(Locale).includes(context.body.locale) ) { locale = context.body.locale; } return { data: { ...user, locale } }; }, async after(user) { await prisma.status.createMany({ data: defaultStatus[(user as User).locale || 'en'].map((status) => ({ ...status, id: createId(), userId: user.id })) }); } } } } }); ``` ### Additional context Created #2874 that fixes the issue.
Author
Owner

@Chandraprakash-Darji commented on GitHub (Sep 26, 2025):

I am on the latest version of the better auth facing this issue still, any workaround?

version 1.3.18

config:

 stripe({
        stripeClient,
        stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET,
        createCustomerOnSignUp: true,
        subscription: {
          enabled: true,
          plans: [
            {
              name: "Basic Plan",
              priceId: "price_1SBU34dJZfsQyg8lCxRRRR",
            },
            {
              name: "Professional Plan",
              priceId: "price_1SBU34dJZfsQyg8lCxRRRR",
            },
            {
              name: "Premium Plan",
              priceId: "price_1SBU34dJZfsQyg8lCxRRRR",
            },
          ],
        },
      }),
@Chandraprakash-Darji commented on GitHub (Sep 26, 2025): I am on the latest version of the better auth facing this issue still, any workaround? version `1.3.18` config: ```ts stripe({ stripeClient, stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET, createCustomerOnSignUp: true, subscription: { enabled: true, plans: [ { name: "Basic Plan", priceId: "price_1SBU34dJZfsQyg8lCxRRRR", }, { name: "Professional Plan", priceId: "price_1SBU34dJZfsQyg8lCxRRRR", }, { name: "Premium Plan", priceId: "price_1SBU34dJZfsQyg8lCxRRRR", }, ], }, }), ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1294