create-better-t-stack 2.46.3-canary.a2097c5b → 2.46.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/{src-C8eRIOI8.js → src-El86OdG5.js} +33 -127
  4. package/package.json +2 -3
  5. package/templates/auth/better-auth/web/react/next/src/components/theme-provider.tsx.hbs +11 -0
  6. package/templates/frontend/react/next/src/components/providers.tsx.hbs +0 -8
  7. package/templates/frontend/react/tanstack-router/src/main.tsx.hbs +1 -8
  8. package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +0 -47
  9. package/templates/frontend/react/tanstack-start/src/routes/index.tsx.hbs +2 -2
  10. package/templates/frontend/react/web-base/src/components/header.tsx.hbs +2 -2
  11. package/templates/auth/better-auth/convex/backend/convex/auth.config.ts.hbs +0 -8
  12. package/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs +0 -48
  13. package/templates/auth/better-auth/convex/backend/convex/convex.config.ts.hbs +0 -7
  14. package/templates/auth/better-auth/convex/backend/convex/http.ts.hbs +0 -12
  15. package/templates/auth/better-auth/convex/backend/convex/privateData.ts.hbs +0 -16
  16. package/templates/auth/better-auth/convex/web/react/next/src/app/api/auth/[...all]/route.ts.hbs +0 -3
  17. package/templates/auth/better-auth/convex/web/react/next/src/app/dashboard/page.tsx.hbs +0 -40
  18. package/templates/auth/better-auth/convex/web/react/next/src/components/sign-in-form.tsx.hbs +0 -129
  19. package/templates/auth/better-auth/convex/web/react/next/src/components/sign-up-form.tsx.hbs +0 -154
  20. package/templates/auth/better-auth/convex/web/react/next/src/components/user-menu.tsx.hbs +0 -48
  21. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-client.ts.hbs +0 -6
  22. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-server.ts.hbs +0 -6
  23. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/sign-in-form.tsx.hbs +0 -133
  24. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/sign-up-form.tsx.hbs +0 -158
  25. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/user-menu.tsx.hbs +0 -50
  26. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs +0 -10
  27. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/routes/dashboard.tsx.hbs +0 -43
  28. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/sign-in-form.tsx.hbs +0 -133
  29. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/sign-up-form.tsx.hbs +0 -158
  30. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/user-menu.tsx.hbs +0 -50
  31. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-client.ts.hbs +0 -6
  32. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs +0 -5
  33. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/api/auth/$.ts.hbs +0 -11
  34. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/dashboard.tsx.hbs +0 -43
  35. /package/templates/frontend/react/web-base/src/components/{loader.tsx.hbs → loader.tsx} +0 -0
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { createBtsCli } from "./src-C8eRIOI8.js";
2
+ import { createBtsCli } from "./src-El86OdG5.js";
3
3
 
4
4
  //#region src/cli.ts
5
5
  createBtsCli().run();
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { builder, createBtsCli, docs, init, router, sponsors } from "./src-C8eRIOI8.js";
2
+ import { builder, createBtsCli, docs, init, router, sponsors } from "./src-El86OdG5.js";
3
3
 
4
4
  export { builder, createBtsCli, docs, init, router, sponsors };
@@ -122,12 +122,11 @@ const dependencyVersionMap = {
122
122
  "@trpc/tanstack-react-query": "^11.5.0",
123
123
  "@trpc/server": "^11.5.0",
124
124
  "@trpc/client": "^11.5.0",
125
- convex: "^1.27.0",
125
+ convex: "^1.25.4",
126
126
  "@convex-dev/react-query": "^0.0.0-alpha.8",
127
127
  "convex-svelte": "^0.0.11",
128
128
  "convex-nuxt": "0.1.5",
129
129
  "convex-vue": "^0.1.5",
130
- "@convex-dev/better-auth": "^0.8.4",
131
130
  "@tanstack/svelte-query": "^5.85.3",
132
131
  "@tanstack/svelte-query-devtools": "^5.85.3",
133
132
  "@tanstack/vue-query-devtools": "^5.83.0",
@@ -424,10 +423,11 @@ function validateAddonsAgainstFrontends(addons = [], frontends = [], auth) {
424
423
  if (!isCompatible) exitWithError(`Incompatible addon/frontend combination: ${reason}`);
425
424
  }
426
425
  }
427
- function validatePaymentsCompatibility(payments, auth, _backend, frontends = []) {
426
+ function validatePaymentsCompatibility(payments, auth, backend, frontends = []) {
428
427
  if (!payments || payments === "none") return;
429
428
  if (payments === "polar") {
430
429
  if (!auth || auth === "none" || auth !== "better-auth") exitWithError("Polar payments requires Better Auth. Please use '--auth better-auth' or choose a different payments provider.");
430
+ if (backend === "convex") exitWithError("Polar payments is not compatible with Convex backend. Please use a different backend or choose a different payments provider.");
431
431
  const { web } = splitFrontends(frontends);
432
432
  if (web.length === 0 && frontends.length > 0) exitWithError("Polar payments requires a web frontend or no frontend. Please select a web frontend or choose a different payments provider.");
433
433
  }
@@ -614,36 +614,20 @@ async function getAuthChoice(auth, hasDatabase, backend, frontend) {
614
614
  const unsupportedFrontends = frontend?.filter((f) => [
615
615
  "nuxt",
616
616
  "svelte",
617
- "solid",
618
- "native-nativewind",
619
- "native-unistyles"
617
+ "solid"
620
618
  ].includes(f));
621
619
  if (unsupportedFrontends && unsupportedFrontends.length > 0) return "none";
622
- const hasReactFrontends = frontend?.some((f) => [
623
- "react-router",
624
- "tanstack-router",
625
- "tanstack-start",
626
- "next"
627
- ].includes(f));
628
- const options = [{
629
- value: "clerk",
630
- label: "Clerk",
631
- hint: "More than auth, Complete User Management"
632
- }];
633
- if (hasReactFrontends) options.unshift({
634
- value: "better-auth",
635
- label: "Better-Auth",
636
- hint: "comprehensive auth framework for TypeScript"
637
- });
638
- options.push({
639
- value: "none",
640
- label: "None",
641
- hint: "No auth"
642
- });
643
620
  const response$1 = await select({
644
621
  message: "Select authentication provider",
645
- options,
646
- initialValue: "none"
622
+ options: [{
623
+ value: "clerk",
624
+ label: "Clerk",
625
+ hint: "More than auth, Complete User Management"
626
+ }, {
627
+ value: "none",
628
+ label: "None"
629
+ }],
630
+ initialValue: "clerk"
647
631
  });
648
632
  if (isCancel(response$1)) return exitCancelled("Operation cancelled");
649
633
  return response$1;
@@ -1386,7 +1370,7 @@ const getLatestCLIVersion = () => {
1386
1370
  */
1387
1371
  function isTelemetryEnabled() {
1388
1372
  const BTS_TELEMETRY_DISABLED = process.env.BTS_TELEMETRY_DISABLED;
1389
- const BTS_TELEMETRY = "0";
1373
+ const BTS_TELEMETRY = "1";
1390
1374
  if (BTS_TELEMETRY_DISABLED !== void 0) return BTS_TELEMETRY_DISABLED !== "1";
1391
1375
  if (BTS_TELEMETRY !== void 0) return BTS_TELEMETRY === "1";
1392
1376
  return true;
@@ -1394,8 +1378,8 @@ function isTelemetryEnabled() {
1394
1378
 
1395
1379
  //#endregion
1396
1380
  //#region src/utils/analytics.ts
1397
- const POSTHOG_API_KEY = "random";
1398
- const POSTHOG_HOST = "random";
1381
+ const POSTHOG_API_KEY = "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs";
1382
+ const POSTHOG_HOST = "https://us.i.posthog.com";
1399
1383
  function generateSessionId() {
1400
1384
  const rand = Math.random().toString(36).slice(2);
1401
1385
  const now = Date.now().toString(36);
@@ -1749,16 +1733,7 @@ function validateConvexConstraints(config, providedFlags) {
1749
1733
  if (has("api") && config.api !== "none") exitWithError("Convex backend requires '--api none'. Please remove the --api flag or set it to 'none'.");
1750
1734
  if (has("dbSetup") && config.dbSetup !== "none") exitWithError("Convex backend requires '--db-setup none'. Please remove the --db-setup flag or set it to 'none'.");
1751
1735
  if (has("serverDeploy") && config.serverDeploy !== "none") exitWithError("Convex backend requires '--server-deploy none'. Please remove the --server-deploy flag or set it to 'none'.");
1752
- if (has("auth") && config.auth === "better-auth") {
1753
- const hasUnsupportedFrontends = config.frontend?.some((f) => [
1754
- "nuxt",
1755
- "svelte",
1756
- "solid",
1757
- "native-nativewind",
1758
- "native-unistyles"
1759
- ].includes(f));
1760
- if (hasUnsupportedFrontends) exitWithError("Better-Auth with Convex backend is not supported for non-React frontends (nuxt, svelte, solid) or native frontends (native-nativewind, native-unistyles). Please use '--auth clerk' or '--auth none'.");
1761
- }
1736
+ if (has("auth") && config.auth === "better-auth") exitWithError("Better-Auth is not compatible with Convex backend. Please use '--auth clerk' or '--auth none'.");
1762
1737
  }
1763
1738
  function validateBackendNoneConstraints(config, providedFlags) {
1764
1739
  const { backend } = config;
@@ -2005,18 +1980,18 @@ async function updateBtsConfig(projectDir, updates) {
2005
1980
  //#endregion
2006
1981
  //#region src/utils/add-package-deps.ts
2007
1982
  const addPackageDependency = async (opts) => {
2008
- const { dependencies = [], devDependencies = [], customDependencies = {}, customDevDependencies = {}, projectDir } = opts;
1983
+ const { dependencies = [], devDependencies = [], projectDir } = opts;
2009
1984
  const pkgJsonPath = path.join(projectDir, "package.json");
2010
1985
  const pkgJson = await fs.readJson(pkgJsonPath);
2011
1986
  if (!pkgJson.dependencies) pkgJson.dependencies = {};
2012
1987
  if (!pkgJson.devDependencies) pkgJson.devDependencies = {};
2013
1988
  for (const pkgName of dependencies) {
2014
- const version = customDependencies[pkgName] || dependencyVersionMap[pkgName];
1989
+ const version = dependencyVersionMap[pkgName];
2015
1990
  if (version) pkgJson.dependencies[pkgName] = version;
2016
1991
  else console.warn(`Warning: Dependency ${pkgName} not found in version map.`);
2017
1992
  }
2018
1993
  for (const pkgName of devDependencies) {
2019
- const version = customDevDependencies[pkgName] || dependencyVersionMap[pkgName];
1994
+ const version = dependencyVersionMap[pkgName];
2020
1995
  if (version) pkgJson.devDependencies[pkgName] = version;
2021
1996
  else console.warn(`Warning: Dev dependency ${pkgName} not found in version map.`);
2022
1997
  }
@@ -2878,29 +2853,6 @@ async function setupAuthTemplate(projectDir, context) {
2878
2853
  }
2879
2854
  return;
2880
2855
  }
2881
- if (context.backend === "convex" && authProvider === "better-auth") {
2882
- const convexBackendDestDir = path.join(projectDir, "packages/backend");
2883
- const convexBetterAuthBackendSrc = path.join(PKG_ROOT, "templates/auth/better-auth/convex/backend");
2884
- if (await fs.pathExists(convexBetterAuthBackendSrc)) {
2885
- await fs.ensureDir(convexBackendDestDir);
2886
- await processAndCopyFiles("**/*", convexBetterAuthBackendSrc, convexBackendDestDir, context);
2887
- }
2888
- if (webAppDirExists && hasReactWeb) {
2889
- const convexBetterAuthWebBaseSrc = path.join(PKG_ROOT, "templates/auth/better-auth/convex/web/react/base");
2890
- if (await fs.pathExists(convexBetterAuthWebBaseSrc)) await processAndCopyFiles("**/*", convexBetterAuthWebBaseSrc, webAppDir, context);
2891
- const reactFramework = context.frontend.find((f) => [
2892
- "tanstack-router",
2893
- "react-router",
2894
- "tanstack-start",
2895
- "next"
2896
- ].includes(f));
2897
- if (reactFramework) {
2898
- const convexBetterAuthWebSrc = path.join(PKG_ROOT, `templates/auth/better-auth/convex/web/react/${reactFramework}`);
2899
- if (await fs.pathExists(convexBetterAuthWebSrc)) await processAndCopyFiles("**/*", convexBetterAuthWebSrc, webAppDir, context);
2900
- }
2901
- }
2902
- return;
2903
- }
2904
2856
  if (serverAppDirExists && context.backend !== "convex") {
2905
2857
  const authServerBaseSrc = path.join(PKG_ROOT, `templates/auth/${authProvider}/server/base`);
2906
2858
  if (await fs.pathExists(authServerBaseSrc)) await processAndCopyFiles("**/*", authServerBaseSrc, serverAppDir, context);
@@ -4294,35 +4246,6 @@ async function setupAuth(config) {
4294
4246
  projectDir: clientDir
4295
4247
  });
4296
4248
  }
4297
- if (auth === "better-auth") {
4298
- const convexBackendDir = path.join(projectDir, "packages/backend");
4299
- const convexBackendDirExists = await fs.pathExists(convexBackendDir);
4300
- if (convexBackendDirExists) await addPackageDependency({
4301
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4302
- customDependencies: { "better-auth": "1.3.8" },
4303
- projectDir: convexBackendDir
4304
- });
4305
- if (clientDirExists) {
4306
- const hasNextJs = frontend.includes("next");
4307
- const hasTanStackStart = frontend.includes("tanstack-start");
4308
- const hasViteReactOther = frontend.some((f) => ["tanstack-router", "react-router"].includes(f));
4309
- if (hasNextJs) await addPackageDependency({
4310
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4311
- customDependencies: { "better-auth": "1.3.8" },
4312
- projectDir: clientDir
4313
- });
4314
- else if (hasTanStackStart) await addPackageDependency({
4315
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4316
- customDependencies: { "better-auth": "1.3.8" },
4317
- projectDir: clientDir
4318
- });
4319
- else if (hasViteReactOther) await addPackageDependency({
4320
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4321
- customDependencies: { "better-auth": "1.3.8" },
4322
- projectDir: clientDir
4323
- });
4324
- }
4325
- }
4326
4249
  const hasNativeWind = frontend.includes("native-nativewind");
4327
4250
  const hasUnistyles = frontend.includes("native-unistyles");
4328
4251
  if (auth === "clerk" && nativeDirExists && (hasNativeWind || hasUnistyles)) await addPackageDependency({
@@ -4480,18 +4403,6 @@ async function setupEnvironmentVariables(config) {
4480
4403
  });
4481
4404
  }
4482
4405
  }
4483
- if (backend === "convex" && auth === "better-auth") {
4484
- if (hasNextJs) clientVars.push({
4485
- key: "NEXT_PUBLIC_CONVEX_SITE_URL",
4486
- value: "https://<YOUR_CONVEX_URL>",
4487
- condition: true
4488
- });
4489
- else if (hasReactRouter || hasTanStackRouter || hasTanStackStart) clientVars.push({
4490
- key: "VITE_CONVEX_SITE_URL",
4491
- value: "https://<YOUR_CONVEX_URL>",
4492
- condition: true
4493
- });
4494
- }
4495
4406
  await addEnvVariablesToFile(path.join(clientDir, ".env"), clientVars);
4496
4407
  }
4497
4408
  }
@@ -4517,24 +4428,7 @@ async function setupEnvironmentVariables(config) {
4517
4428
  await addEnvVariablesToFile(path.join(nativeDir, ".env"), nativeVars);
4518
4429
  }
4519
4430
  }
4520
- if (backend === "convex") {
4521
- if (auth === "better-auth") {
4522
- const convexBackendDir = path.join(projectDir, "packages/backend");
4523
- if (await fs.pathExists(convexBackendDir)) {
4524
- const convexBackendVars = [{
4525
- key: hasTanStackStart ? "NEXT_PUBLIC_CONVEX_SITE_URL" : "VITE_CONVEX_SITE_URL",
4526
- value: "",
4527
- condition: true
4528
- }, {
4529
- key: "SITE_URL",
4530
- value: "http://localhost:3001",
4531
- condition: true
4532
- }];
4533
- await addEnvVariablesToFile(path.join(convexBackendDir, ".env.local"), convexBackendVars);
4534
- }
4535
- }
4536
- return;
4537
- }
4431
+ if (backend === "convex") return;
4538
4432
  const serverDir = path.join(projectDir, "apps/server");
4539
4433
  if (!await fs.pathExists(serverDir)) return;
4540
4434
  const envPath = path.join(serverDir, ".env");
@@ -5819,6 +5713,17 @@ async function setupNodeRuntime(serverDir, backend) {
5819
5713
  });
5820
5714
  }
5821
5715
 
5716
+ //#endregion
5717
+ //#region src/helpers/core/convex-codegen.ts
5718
+ async function runConvexCodegen(projectDir, packageManager) {
5719
+ const backendDir = path.join(projectDir, "packages/backend");
5720
+ const cmd = getPackageExecutionCommand(packageManager, "convex codegen");
5721
+ await execa(cmd, {
5722
+ cwd: backendDir,
5723
+ shell: true
5724
+ });
5725
+ }
5726
+
5822
5727
  //#endregion
5823
5728
  //#region src/helpers/core/create-readme.ts
5824
5729
  async function createReadme(projectDir, options) {
@@ -6610,6 +6515,7 @@ async function createProject(options, cliInput) {
6610
6515
  await setupServerDeploy(options);
6611
6516
  await createReadme(projectDir, options);
6612
6517
  await writeBtsConfig(options);
6518
+ if (isConvex) await runConvexCodegen(projectDir, options.packageManager);
6613
6519
  log.success("Project template successfully scaffolded!");
6614
6520
  if (options.install) await installDependencies({
6615
6521
  projectDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "2.46.3-canary.a2097c5b",
3
+ "version": "2.46.3",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "homepage": "https://better-t-stack.dev/",
50
50
  "scripts": {
51
- "build": "tsdown --publint",
51
+ "build": "tsdown",
52
52
  "dev": "tsdown --watch",
53
53
  "check-types": "tsc --noEmit",
54
54
  "check": "biome check --write .",
@@ -82,7 +82,6 @@
82
82
  "@types/fs-extra": "^11.0.4",
83
83
  "@types/node": "^24.3.1",
84
84
  "@vitest/ui": "^3.2.4",
85
- "publint": "^0.3.12",
86
85
  "tsdown": "^0.14.2",
87
86
  "typescript": "^5.9.2",
88
87
  "vitest": "^3.2.4"
@@ -0,0 +1,11 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { ThemeProvider as NextThemesProvider } from "next-themes"
5
+
6
+ export function ThemeProvider({
7
+ children,
8
+ ...props
9
+ }: React.ComponentProps<typeof NextThemesProvider>) {
10
+ return <NextThemesProvider {...props}>{children}</NextThemesProvider>
11
+ }
@@ -5,10 +5,6 @@
5
5
  import { useAuth } from "@clerk/nextjs";
6
6
  import { ConvexReactClient } from "convex/react";
7
7
  import { ConvexProviderWithClerk } from "convex/react-clerk";
8
- {{else if (eq auth "better-auth")}}
9
- import { ConvexProvider, ConvexReactClient } from "convex/react";
10
- import { ConvexBetterAuthProvider } from "@convex-dev/better-auth/react";
11
- import { authClient } from "@/lib/auth-client";
12
8
  {{else}}
13
9
  import { ConvexProvider, ConvexReactClient } from "convex/react";
14
10
  {{/if}}
@@ -48,10 +44,6 @@ export default function Providers({
48
44
  <ConvexProviderWithClerk client={convex} useAuth={useAuth}>
49
45
  {children}
50
46
  </ConvexProviderWithClerk>
51
- {{else if (eq auth "better-auth")}}
52
- <ConvexBetterAuthProvider client={convex} authClient={authClient}>
53
- {children}
54
- </ConvexBetterAuthProvider>
55
47
  {{else}}
56
48
  <ConvexProvider client={convex}>{children}</ConvexProvider>
57
49
  {{/if}}
@@ -16,15 +16,10 @@ import { routeTree } from "./routeTree.gen";
16
16
  {{#if (eq auth "clerk")}}
17
17
  import { ClerkProvider, useAuth } from "@clerk/clerk-react";
18
18
  import { ConvexProviderWithClerk } from "convex/react-clerk";
19
- {{else if (eq auth "better-auth")}}
20
- import { ConvexBetterAuthProvider } from "@convex-dev/better-auth/react";
21
- import { authClient } from "@/lib/auth-client";
22
19
  {{else}}
23
20
  import { ConvexProvider } from "convex/react";
24
21
  {{/if}}
25
- const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL as string{{#if (eq auth "better-auth")}}, {
26
- expectAuth: true,
27
- }{{/if}});
22
+ const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL as string);
28
23
  {{/if}}
29
24
 
30
25
  const router = createRouter({
@@ -62,8 +57,6 @@ const router = createRouter({
62
57
  </ConvexProviderWithClerk>
63
58
  </ClerkProvider>
64
59
  );
65
- {{else if (eq auth "better-auth")}}
66
- return <ConvexBetterAuthProvider client={convex} authClient={authClient}>{children}</ConvexBetterAuthProvider>;
67
60
  {{else}}
68
61
  return <ConvexProvider client={convex}>{children}</ConvexProvider>;
69
62
  {{/if}}
@@ -8,9 +8,7 @@ import {
8
8
  Scripts,
9
9
  createRootRouteWithContext,
10
10
  useRouterState,
11
- {{#if (and (eq backend "convex") (or (eq auth "clerk") (eq auth "better-auth")))}}
12
11
  useRouteContext,
13
- {{/if}}
14
12
  } from "@tanstack/react-router";
15
13
  import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
16
14
  import Header from "../components/header";
@@ -38,23 +36,6 @@ const fetchClerkAuth = createServerFn({ method: "GET" }).handler(async () => {
38
36
  const token = await auth.getToken({ template: "convex" });
39
37
  return { userId: auth.userId, token };
40
38
  });
41
- {{else if (and (eq backend "convex") (eq auth "better-auth"))}}
42
- import { createServerFn } from "@tanstack/react-start";
43
- import { getWebRequest, getCookie } from "@tanstack/react-start/server";
44
- import { ConvexBetterAuthProvider } from "@convex-dev/better-auth/react";
45
- import { fetchSession, getCookieName } from "@convex-dev/better-auth/react-start";
46
- import { authClient } from "@/lib/auth-client";
47
- import { createAuth } from "@{{projectName}}/backend/convex/auth";
48
-
49
- const fetchAuth = createServerFn({ method: "GET" }).handler(async () => {
50
- const { session } = await fetchSession(getWebRequest());
51
- const sessionCookieName = getCookieName(createAuth);
52
- const token = getCookie(sessionCookieName);
53
- return {
54
- userId: session?.user.id,
55
- token,
56
- };
57
- });
58
39
  {{/if}}
59
40
 
60
41
  {{#if (eq backend "convex")}}
@@ -114,14 +95,6 @@ export const Route = createRootRouteWithContext<RouterAppContext>()({
114
95
  }
115
96
  return { userId, token };
116
97
  },
117
- {{else if (and (eq backend "convex") (eq auth "better-auth"))}}
118
- beforeLoad: async (ctx) => {
119
- const { userId, token } = await fetchAuth();
120
- if (token) {
121
- ctx.context.convexQueryClient.serverHttpClient?.setAuth(token);
122
- }
123
- return { userId, token };
124
- },
125
98
  {{/if}}
126
99
  });
127
100
 
@@ -149,26 +122,6 @@ function RootDocument() {
149
122
  </ConvexProviderWithClerk>
150
123
  </ClerkProvider>
151
124
  );
152
- {{else if (and (eq backend "convex") (eq auth "better-auth"))}}
153
- const context = useRouteContext({ from: Route.id });
154
- return (
155
- <ConvexBetterAuthProvider client={context.convexClient} authClient={authClient}>
156
- <html lang="en" className="dark">
157
- <head>
158
- <HeadContent />
159
- </head>
160
- <body>
161
- <div className="grid h-svh grid-rows-[auto_1fr]">
162
- <Header />
163
- {isFetching ? <Loader /> : <Outlet />}
164
- </div>
165
- <Toaster richColors />
166
- <TanStackRouterDevtools position="bottom-left" />
167
- <Scripts />
168
- </body>
169
- </html>
170
- </ConvexBetterAuthProvider>
171
- );
172
125
  {{else}}
173
126
  return (
174
127
  <html lang="en" className="dark">
@@ -1,7 +1,7 @@
1
1
  import { createFileRoute } from "@tanstack/react-router";
2
2
  {{#if (eq backend "convex")}}
3
3
  import { convexQuery } from "@convex-dev/react-query";
4
- import { useQuery } from "@tanstack/react-query";
4
+ import { useSuspenseQuery } from "@tanstack/react-query";
5
5
  import { api } from "@{{projectName}}/backend/convex/_generated/api";
6
6
  {{else if (or (eq api "trpc") (eq api "orpc"))}}
7
7
  import { useQuery } from "@tanstack/react-query";
@@ -35,7 +35,7 @@ const TITLE_TEXT = `
35
35
 
36
36
  function HomeComponent() {
37
37
  {{#if (eq backend "convex")}}
38
- const healthCheck = useQuery(convexQuery(api.healthCheck.get, {}));
38
+ const healthCheck = useSuspenseQuery(convexQuery(api.healthCheck.get, {}));
39
39
  {{else if (eq api "trpc")}}
40
40
  const trpc = useTRPC();
41
41
  const healthCheck = useQuery(trpc.healthCheck.queryOptions());
@@ -9,7 +9,7 @@ import { Link } from "@tanstack/react-router";
9
9
  {{#unless (includes frontend "tanstack-start")}}
10
10
  import { ModeToggle } from "./mode-toggle";
11
11
  {{/unless}}
12
- {{#if (and (eq auth "better-auth") (ne backend "convex"))}}
12
+ {{#if (eq auth "better-auth")}}
13
13
  import UserMenu from "./user-menu";
14
14
  {{/if}}
15
15
 
@@ -67,7 +67,7 @@ export default function Header() {
67
67
  {{#unless (includes frontend "tanstack-start")}}
68
68
  <ModeToggle />
69
69
  {{/unless}}
70
- {{#if (and (eq auth "better-auth") (ne backend "convex"))}}
70
+ {{#if (eq auth "better-auth")}}
71
71
  <UserMenu />
72
72
  {{/if}}
73
73
  </div>
@@ -1,8 +0,0 @@
1
- export default {
2
- providers: [
3
- {
4
- domain: process.env.CONVEX_SITE_URL,
5
- applicationID: "convex",
6
- },
7
- ],
8
- };
@@ -1,48 +0,0 @@
1
- import { createClient, type GenericCtx } from "@convex-dev/better-auth";
2
- {{#if (or (eq frontend "tanstack-start") (eq frontend "next"))}}
3
- import { convex } from "@convex-dev/better-auth/plugins";
4
- {{else}}
5
- import { convex, crossDomain } from "@convex-dev/better-auth/plugins";
6
- {{/if}}
7
- import { components } from "./_generated/api";
8
- import { DataModel } from "./_generated/dataModel";
9
- import { query } from "./_generated/server";
10
- import { betterAuth } from "better-auth";
11
-
12
- const siteUrl = process.env.SITE_URL!;
13
-
14
- export const authComponent = createClient<DataModel>(components.betterAuth);
15
-
16
- export const createAuth = (
17
- ctx: GenericCtx<DataModel>,
18
- { optionsOnly } = { optionsOnly: false },
19
- ) => {
20
- return betterAuth({
21
- logger: {
22
- disabled: optionsOnly,
23
- },
24
- {{#if (or (eq frontend "tanstack-start") (eq frontend "next"))}}
25
- baseUrl: siteUrl,
26
- {{else}}
27
- trustedOrigins: [siteUrl],
28
- {{/if}}
29
- database: authComponent.adapter(ctx),
30
- emailAndPassword: {
31
- enabled: true,
32
- requireEmailVerification: false,
33
- },
34
- plugins: [
35
- {{#unless (or (eq frontend "tanstack-start") (eq frontend "next"))}}
36
- crossDomain({ siteUrl }),
37
- {{/unless}}
38
- convex(),
39
- ],
40
- });
41
- };
42
-
43
- export const getCurrentUser = query({
44
- args: {},
45
- handler: async (ctx) => {
46
- return authComponent.getAuthUser(ctx);
47
- },
48
- });
@@ -1,7 +0,0 @@
1
- import { defineApp } from "convex/server";
2
- import betterAuth from "@convex-dev/better-auth/convex.config";
3
-
4
- const app = defineApp();
5
- app.use(betterAuth);
6
-
7
- export default app;
@@ -1,12 +0,0 @@
1
- import { httpRouter } from "convex/server";
2
- import { authComponent, createAuth } from "./auth";
3
-
4
- const http = httpRouter();
5
-
6
- {{#if (or (eq frontend "tanstack-start") (eq frontend "next"))}}
7
- authComponent.registerRoutes(http, createAuth);
8
- {{else}}
9
- authComponent.registerRoutes(http, createAuth, { cors: true });
10
- {{/if}}
11
-
12
- export default http;
@@ -1,16 +0,0 @@
1
- import { query } from "./_generated/server";
2
-
3
- export const get = query({
4
- args: {},
5
- handler: async (ctx) => {
6
- const identity = await ctx.auth.getUserIdentity();
7
- if (identity === null) {
8
- return {
9
- message: "Not authenticated",
10
- };
11
- }
12
- return {
13
- message: "This is private",
14
- };
15
- },
16
- });
@@ -1,3 +0,0 @@
1
- import { nextJsHandler } from "@convex-dev/better-auth/nextjs";
2
-
3
- export const { GET, POST } = nextJsHandler();
@@ -1,40 +0,0 @@
1
- "use client"
2
-
3
- import SignInForm from "@/components/sign-in-form";
4
- import SignUpForm from "@/components/sign-up-form";
5
- import UserMenu from "@/components/user-menu";
6
- import { api } from "@{{projectName}}/backend/convex/_generated/api";
7
- import {
8
- Authenticated,
9
- AuthLoading,
10
- Unauthenticated,
11
- useQuery,
12
- } from "convex/react";
13
- import { useState } from "react";
14
-
15
- export default function DashboardPage() {
16
- const [showSignIn, setShowSignIn] = useState(false);
17
- const privateData = useQuery(api.privateData.get);
18
-
19
- return (
20
- <>
21
- <Authenticated>
22
- <div>
23
- <h1>Dashboard</h1>
24
- <p>privateData: {privateData?.message}</p>
25
- <UserMenu />
26
- </div>
27
- </Authenticated>
28
- <Unauthenticated>
29
- {showSignIn ? (
30
- <SignInForm onSwitchToSignUp={() => setShowSignIn(false)} />
31
- ) : (
32
- <SignUpForm onSwitchToSignIn={() => setShowSignIn(true)} />
33
- )}
34
- </Unauthenticated>
35
- <AuthLoading>
36
- <div>Loading...</div>
37
- </AuthLoading>
38
- </>
39
- );
40
- }