From b179c0d91a8e93cd0d259d4540801a8dc64eeea0 Mon Sep 17 00:00:00 2001 From: Alexander Klusa <71306750+aklusa022@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:29:40 -0600 Subject: [PATCH 1/3] Document known issues and fixes for Stripe integration Added known issues and mitigations for Stripe createCustomerOnSignUp error, including installation of the Buffer package and necessary code adjustments. --- docs/content/docs/features/local-install.mdx | 109 +++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/docs/content/docs/features/local-install.mdx b/docs/content/docs/features/local-install.mdx index 9567a5b..4f90b64 100644 --- a/docs/content/docs/features/local-install.mdx +++ b/docs/content/docs/features/local-install.mdx @@ -269,3 +269,112 @@ export const someFunction = query({ }, }); ``` + +# Known Issues & Mitigations + + +## Stripe createCustomerOnSignUp CONVEX Uncaught ReferenceError Fix + +Example of error: +```ts +11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] [LOG] '2025-11-15T20:49:55.811Z INFO [Better Auth]: [Convex Adapter]' '#5 \x1B[40m\x1B[33m[4/4]\x1B[0m' '\x1B[1mcreate\x1B[0m \x1B[2m(Parsed Result)\x1B[0m:' { + model: 'user', + data: { + name: 'Alexander K', + email: 'xxxxx@gmail.com', + emailVerified: true, + image: 'https://avatars.githubusercontent.com/u/xxxxxx', + createdAt: 1763239795775, + updatedAt: 1763239795775, + userId: undefined, + stripeCustomerId: undefined, + id: '12345234234' + } +} +11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] Uncaught ReferenceError: Buffer is not defined +``` + +This usually occurs when passing +```ts +createCustomerOnSignUp: true +``` +in the @betterauth/stripe plugin initialization in convex/auth.ts +```ts +plugins: [ + // The Convex plugin is required for Convex compatibility + + convex(), + stripe({ + createCustomerOnSignUp: true, + stripeClient: stripeClient, + stripeWebhookSecret: "xxxxxx" + }), + + ], +``` + +### The fix: + +
+ +
+ + ### Install Buffer Package + + Export adapter functions for the component. + + ```ts title="cli" + npm i buffer + ``` + +
+ +
+ + ### Add Code + Add the following lines to fix the issue + + ```ts title="convex/auth.ts" + + + import { Buffer } from 'buffer'; // [!code ++] + + //all other import statements in auth.ts + + + globalThis.Buffer = Buffer; // [!code ++] + + const stripeClient = new Stripe(process.env.STRIPE_SECRET_KEY, { + //stripe client code args + }) + + + const siteUrl = process.env.SITE_URL!; + + export const authComponent = createClient( + //authComponent code args + ); + ``` + +
+ +
+ globalThis.Buffer = globalThis.Buffer || { // [!code ++ + } as any; // [!code ++ + + + export const createAuth = ( + ctx: GenericCtx, + { optionsOnly } = { optionsOnly: false }, + ) => { + return betterAuth({ + ///your better auth code + }); + }; +
+
+ + + + + From 9af83854bb65be0ba45e1466b0b61cddb759da3f Mon Sep 17 00:00:00 2001 From: Alexander Klusa <71306750+aklusa022@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:46:37 -0600 Subject: [PATCH 2/3] Fix formatting in local-install.mdx --- docs/content/docs/features/local-install.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/docs/features/local-install.mdx b/docs/content/docs/features/local-install.mdx index 4f90b64..8d5244c 100644 --- a/docs/content/docs/features/local-install.mdx +++ b/docs/content/docs/features/local-install.mdx @@ -359,8 +359,8 @@ plugins: [
- globalThis.Buffer = globalThis.Buffer || { // [!code ++ - } as any; // [!code ++ + globalThis.Buffer = globalThis.Buffer || { // [!code ++] + } as any; // [!code ++] export const createAuth = ( From 6e1698886bc659497132337ca44bdfe4f3065dae Mon Sep 17 00:00:00 2001 From: Alexander Klusa Date: Tue, 18 Nov 2025 13:41:10 -0600 Subject: [PATCH 3/3] Update local-install.mdx --- docs/content/docs/features/local-install.mdx | 168 ++++++++++--------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/docs/content/docs/features/local-install.mdx b/docs/content/docs/features/local-install.mdx index 8d5244c..d6dc3a8 100644 --- a/docs/content/docs/features/local-install.mdx +++ b/docs/content/docs/features/local-install.mdx @@ -26,9 +26,9 @@ installation experience with other providers. ### Create the component definition -Create a `convex/betterAuth/convex.config.ts` file to define the component. This -will signal to Convex that the `convex/betterAuth` directory is a locally -installed component. + Create a `convex/betterAuth/convex.config.ts` file to define the component. This + will signal to Convex that the `convex/betterAuth` directory is a locally + installed component. ```ts title="convex/betterAuth/convex.config.ts" import { defineComponent } from "convex/server"; @@ -75,14 +75,14 @@ installed component. import { createAuth } from "../auth"; export const { - create, - findOne, - findMany, - updateOne, - updateMany, - deleteOne, - deleteMany, - } = createApi(schema, createAuth); + create, + findOne, + findMany, + updateOne, + updateMany, + deleteOne, + deleteMany, + } = createApi(schema, createAuth); ```
@@ -118,13 +118,13 @@ installed component. export const authComponent = createClient(components.betterAuth); // [!code --] export const authComponent = createClient( // [!code ++] - components.betterAuth, - // [!code ++:5] - { - local: { - schema: authSchema, - }, - } + components.betterAuth, + // [!code ++:5] + { + local: { + schema: authSchema, + }, + } ); // ... @@ -199,10 +199,10 @@ custom indexes aren't overwritten when the schema is regenerated. import { tables } from "./generatedSchema"; const schema = defineSchema({ - ...tables, - // Spread the generated schema and add a custom index - user: tables.user.index("custom_index", ["field1", "field2"]), - }); + ...tables, + // Spread the generated schema and add a custom index + user: tables.user.index("custom_index", ["field1", "field2"]), + }); export default schema; ``` @@ -235,21 +235,21 @@ import { v } from "convex/values"; // This is accessible from outside the component export const someFunction = query({ - args: { sessionId: v.id("session") }, - // Add a return validator so the return value is typed when - // called from outside the component. - returns: v.union(v.null(), doc(schema, "session")), +args: { sessionId: v.id("session") }, +// Add a return validator so the return value is typed when +// called from outside the component. +returns: v.union(v.null(), doc(schema, "session")), handler: async (ctx, args) => { - return await ctx.db.get(args.sessionId); - }, + return await ctx.db.get(args.sessionId); +}, }); // This is not accessible from outside the component. export const someInternalFunction = internalQuery({ - args: { sessionId: v.id("session") }, - handler: async (ctx, args) => { - return await ctx.db.get(args.sessionId); - }, +args: { sessionId: v.id("session") }, +handler: async (ctx, args) => { + return await ctx.db.get(args.sessionId); +}, }); ``` @@ -261,25 +261,31 @@ import { components } from "./_generated/api"; import { v } from "convex/values"; export const someFunction = query({ - args: { sessionId: v.id("session") }, - handler: async (ctx, args) => { - return await ctx.runQuery(components.betterAuth.someFile.someFunction, { - sessionId: args.sessionId, - }); - }, +args: { sessionId: v.id("session") }, +handler: async (ctx, args) => { + return await ctx.runQuery(components.betterAuth.someFile.someFunction, { + sessionId: args.sessionId, + }); +}, }); ``` -# Known Issues & Mitigations +### Stripe createCustomerOnSignUp CONVEX Uncaught ReferenceError Fix + + + If you are installing the `@better-auth/stripe` package, you will encounter the following error when using the createCustomerOnSignUp + + +
-## Stripe createCustomerOnSignUp CONVEX Uncaught ReferenceError Fix +
-Example of error: -```ts -11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] [LOG] '2025-11-15T20:49:55.811Z INFO [Better Auth]: [Convex Adapter]' '#5 \x1B[40m\x1B[33m[4/4]\x1B[0m' '\x1B[1mcreate\x1B[0m \x1B[2m(Parsed Result)\x1B[0m:' { - model: 'user', - data: { + Example of error with default local installation: + ```ts + 11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] [LOG] '2025-11-15T20:49:55.811Z INFO [Better Auth]: [Convex Adapter]' '#5 \x1B[40m\x1B[33m[4/4]\x1B[0m' '\x1B[1mcreate\x1B[0m \x1B[2m(Parsed Result)\x1B[0m:' { + model: 'user', + data: { name: 'Alexander K', email: 'xxxxx@gmail.com', emailVerified: true, @@ -290,32 +296,33 @@ Example of error: stripeCustomerId: undefined, id: '12345234234' } -} -11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] Uncaught ReferenceError: Buffer is not defined -``` + } + 11/15/2025, 2:49:55 PM [CONVEX H(GET /api/auth/callback/github)] Uncaught ReferenceError: Buffer is not defined + ``` +
+
+ + ### This usually occurs when passing + ```ts + createCustomerOnSignUp: true + ``` + in the @betterauth/stripe plugin initialization in convex/auth.ts + ```ts + plugins: [ + + convex(), + stripe({ + createCustomerOnSignUp: true, + stripeClient: stripeClient, + stripeWebhookSecret: "xxxxxx" + }), + + ], + ``` +
-This usually occurs when passing -```ts -createCustomerOnSignUp: true -``` -in the @betterauth/stripe plugin initialization in convex/auth.ts -```ts -plugins: [ - // The Convex plugin is required for Convex compatibility - - convex(), - stripe({ - createCustomerOnSignUp: true, - stripeClient: stripeClient, - stripeWebhookSecret: "xxxxxx" - }), - - ], -``` -### The fix: -
@@ -346,32 +353,33 @@ plugins: [ const stripeClient = new Stripe(process.env.STRIPE_SECRET_KEY, { //stripe client code args - }) + }) const siteUrl = process.env.SITE_URL!; export const authComponent = createClient( - //authComponent code args + //authComponent code args ); - ``` -
- -
globalThis.Buffer = globalThis.Buffer || { // [!code ++] - } as any; // [!code ++] + //Dont put anything here [!code ++] + } as any; // [!code ++] export const createAuth = ( - ctx: GenericCtx, - { optionsOnly } = { optionsOnly: false }, + ctx: GenericCtx, + { optionsOnly } = { optionsOnly: false }, ) => { - return betterAuth({ - ///your better auth code - }); + return betterAuth({ + ///your better auth code + }); }; + + ``` +
+