@@ -2370,9 +2370,7 @@ describe('cli/cli', () => {
23702370 path . join ( dir , 'lib' , 'convex' , 'auth-client.ts' ) ,
23712371 'utf8'
23722372 ) ;
2373- expect ( authClientSource ) . toContain (
2374- 'process.env.NEXT_PUBLIC_CONVEX_SITE_URL!'
2375- ) ;
2373+ expect ( authClientSource ) . toContain ( 'process.env.NEXT_PUBLIC_SITE_URL!' ) ;
23762374 expect ( authClientSource ) . not . toContain ( 'createAuthMutations' ) ;
23772375
23782376 const schemaSource = fs . readFileSync (
@@ -2474,9 +2472,7 @@ describe('cli/cli', () => {
24742472 path . join ( dir , 'src' , 'lib' , 'convex' , 'auth-client.ts' ) ,
24752473 'utf8'
24762474 ) ;
2477- expect ( authClientSource ) . toContain (
2478- 'import.meta.env.VITE_CONVEX_SITE_URL!'
2479- ) ;
2475+ expect ( authClientSource ) . toContain ( 'import.meta.env.VITE_SITE_URL!' ) ;
24802476 expect ( authClientSource ) . not . toContain ( 'createAuthMutations' ) ;
24812477 expect (
24822478 execaStub . mock . calls . some ( ( call ) => {
@@ -2566,9 +2562,7 @@ describe('cli/cli', () => {
25662562 path . join ( dir , 'src' , 'lib' , 'convex' , 'auth-client.ts' ) ,
25672563 'utf8'
25682564 ) ;
2569- expect ( authClientSource ) . toContain (
2570- 'import.meta.env.VITE_CONVEX_SITE_URL!'
2571- ) ;
2565+ expect ( authClientSource ) . toContain ( 'import.meta.env.VITE_SITE_URL!' ) ;
25722566 expect ( authClientSource ) . not . toContain ( 'createAuthMutations' ) ;
25732567
25742568 const httpSource = fs . readFileSync (
@@ -2683,6 +2677,84 @@ describe('cli/cli', () => {
26832677 }
26842678 } ) ;
26852679
2680+ test ( 'run(add auth --preset convex --yes) preserves a user-edited raw start auth client on rerun' , async ( ) => {
2681+ const dir = fs . mkdtempSync (
2682+ path . join ( os . tmpdir ( ) , 'kitcn-cli-add-auth-convex-start-auth-client-' )
2683+ ) ;
2684+ const oldCwd = process . cwd ( ) ;
2685+ writeRawConvexStartApp ( dir ) ;
2686+ fs . writeFileSync (
2687+ path . join ( dir , '.env.local' ) ,
2688+ 'CONVEX_DEPLOYMENT=local:demo\nVITE_CONVEX_URL=http://127.0.0.1:3210\n'
2689+ ) ;
2690+ process . chdir ( dir ) ;
2691+
2692+ try {
2693+ const execaStub = mock ( async ( _cmd : string , args : string [ ] ) => {
2694+ if ( args [ 0 ] === '/fake/convex/main.js' && args [ 1 ] === 'codegen' ) {
2695+ return { exitCode : 0 , stdout : '' , stderr : '' } as any ;
2696+ }
2697+
2698+ return { exitCode : 0 } as any ;
2699+ } ) ;
2700+ const generateMetaStub = mock ( async ( ) => { } ) ;
2701+ const syncEnvStub = mock ( async ( ) => { } ) ;
2702+ const loadConfigStub = mock ( ( ) => createDefaultConfig ( ) ) ;
2703+
2704+ await run ( [ 'add' , 'auth' , '--preset' , 'convex' , '--yes' ] , {
2705+ realConvex : '/fake/convex/main.js' ,
2706+ execa : execaStub as any ,
2707+ generateMeta : generateMetaStub as any ,
2708+ syncEnv : syncEnvStub as any ,
2709+ loadCliConfig : loadConfigStub as any ,
2710+ } ) ;
2711+
2712+ const authClientPath = path . join (
2713+ dir ,
2714+ 'src' ,
2715+ 'lib' ,
2716+ 'convex' ,
2717+ 'auth-client.ts'
2718+ ) ;
2719+ const editedAuthClientSource = `${ fs . readFileSync ( authClientPath , 'utf8' ) }
2720+ // user plugin
2721+ ` ;
2722+ fs . writeFileSync ( authClientPath , editedAuthClientSource , 'utf8' ) ;
2723+ const nodeModulesDir = path . join ( dir , 'node_modules' ) ;
2724+ fs . mkdirSync ( nodeModulesDir , { recursive : true } ) ;
2725+ fs . symlinkSync (
2726+ path . join ( oldCwd , 'packages' , 'kitcn' ) ,
2727+ path . join ( nodeModulesDir , 'kitcn' )
2728+ ) ;
2729+ fs . symlinkSync (
2730+ path . join ( oldCwd , 'node_modules' , 'better-auth' ) ,
2731+ path . join ( nodeModulesDir , 'better-auth' )
2732+ ) ;
2733+ fs . symlinkSync (
2734+ path . join ( oldCwd , 'node_modules' , 'zod' ) ,
2735+ path . join ( nodeModulesDir , 'zod' )
2736+ ) ;
2737+
2738+ const exitCode = await run (
2739+ [ 'add' , 'auth' , '--preset' , 'convex' , '--yes' , '--no-codegen' ] ,
2740+ {
2741+ realConvex : '/fake/convex/main.js' ,
2742+ execa : execaStub as any ,
2743+ generateMeta : generateMetaStub as any ,
2744+ syncEnv : syncEnvStub as any ,
2745+ loadCliConfig : loadConfigStub as any ,
2746+ }
2747+ ) ;
2748+
2749+ expect ( exitCode ) . toBe ( 0 ) ;
2750+ expect ( fs . readFileSync ( authClientPath , 'utf8' ) ) . toBe (
2751+ editedAuthClientSource
2752+ ) ;
2753+ } finally {
2754+ process . chdir ( oldCwd ) ;
2755+ }
2756+ } ) ;
2757+
26862758 test ( 'run(add ratelimit/auth/resend --yes --no-codegen) keeps auth in root schema and other plugins in one ordered extend call' , async ( ) => {
26872759 const dir = fs . mkdtempSync (
26882760 path . join ( os . tmpdir ( ) , 'kitcn-cli-add-plugin-stack-' )
0 commit comments