create-better-t-stack 2.46.0-canary.c8dd04fa → 2.46.1

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 (36) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/{src-lN80CwOs.js → src-NOw0j6Z9.js} +32 -126
  4. package/package.json +1 -1
  5. package/templates/auth/better-auth/web/react/next/src/components/theme-provider.tsx.hbs +11 -0
  6. package/templates/backend/server/hono/src/index.ts.hbs +1 -1
  7. package/templates/frontend/react/next/src/components/providers.tsx.hbs +0 -8
  8. package/templates/frontend/react/tanstack-router/src/main.tsx.hbs +1 -8
  9. package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +0 -47
  10. package/templates/frontend/react/tanstack-start/src/routes/index.tsx.hbs +2 -2
  11. package/templates/frontend/react/web-base/src/components/header.tsx.hbs +2 -2
  12. package/templates/auth/better-auth/convex/backend/convex/auth.config.ts.hbs +0 -8
  13. package/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs +0 -48
  14. package/templates/auth/better-auth/convex/backend/convex/convex.config.ts.hbs +0 -7
  15. package/templates/auth/better-auth/convex/backend/convex/http.ts.hbs +0 -12
  16. package/templates/auth/better-auth/convex/backend/convex/privateData.ts.hbs +0 -16
  17. package/templates/auth/better-auth/convex/web/react/next/src/app/api/auth/[...all]/route.ts.hbs +0 -3
  18. package/templates/auth/better-auth/convex/web/react/next/src/app/dashboard/page.tsx.hbs +0 -40
  19. package/templates/auth/better-auth/convex/web/react/next/src/components/sign-in-form.tsx.hbs +0 -129
  20. package/templates/auth/better-auth/convex/web/react/next/src/components/sign-up-form.tsx.hbs +0 -154
  21. package/templates/auth/better-auth/convex/web/react/next/src/components/user-menu.tsx.hbs +0 -48
  22. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-client.ts.hbs +0 -6
  23. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-server.ts.hbs +0 -6
  24. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/sign-in-form.tsx.hbs +0 -133
  25. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/sign-up-form.tsx.hbs +0 -158
  26. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/user-menu.tsx.hbs +0 -50
  27. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs +0 -10
  28. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/routes/dashboard.tsx.hbs +0 -43
  29. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/sign-in-form.tsx.hbs +0 -133
  30. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/sign-up-form.tsx.hbs +0 -158
  31. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/user-menu.tsx.hbs +0 -50
  32. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-client.ts.hbs +0 -6
  33. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs +0 -5
  34. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/api/auth/$.ts.hbs +0 -11
  35. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/dashboard.tsx.hbs +0 -43
  36. /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-lN80CwOs.js";
2
+ import { createBtsCli } from "./src-NOw0j6Z9.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-lN80CwOs.js";
2
+ import { builder, createBtsCli, docs, init, router, sponsors } from "./src-NOw0j6Z9.js";
3
3
 
4
4
  export { builder, createBtsCli, docs, init, router, sponsors };
@@ -126,7 +126,6 @@ const dependencyVersionMap = {
126
126
  "convex-svelte": "^0.0.11",
127
127
  "convex-nuxt": "0.1.5",
128
128
  "convex-vue": "^0.1.5",
129
- "@convex-dev/better-auth": "^0.8.4",
130
129
  "@tanstack/svelte-query": "^5.85.3",
131
130
  "@tanstack/svelte-query-devtools": "^5.85.3",
132
131
  "@tanstack/vue-query-devtools": "^5.83.0",
@@ -423,10 +422,11 @@ function validateAddonsAgainstFrontends(addons = [], frontends = [], auth) {
423
422
  if (!isCompatible) exitWithError(`Incompatible addon/frontend combination: ${reason}`);
424
423
  }
425
424
  }
426
- function validatePaymentsCompatibility(payments, auth, _backend, frontends = []) {
425
+ function validatePaymentsCompatibility(payments, auth, backend, frontends = []) {
427
426
  if (!payments || payments === "none") return;
428
427
  if (payments === "polar") {
429
428
  if (!auth || auth === "none" || auth !== "better-auth") exitWithError("Polar payments requires Better Auth. Please use '--auth better-auth' or choose a different payments provider.");
429
+ if (backend === "convex") exitWithError("Polar payments is not compatible with Convex backend. Please use a different backend or choose a different payments provider.");
430
430
  const { web } = splitFrontends(frontends);
431
431
  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.");
432
432
  }
@@ -613,36 +613,20 @@ async function getAuthChoice(auth, hasDatabase, backend, frontend) {
613
613
  const unsupportedFrontends = frontend?.filter((f) => [
614
614
  "nuxt",
615
615
  "svelte",
616
- "solid",
617
- "native-nativewind",
618
- "native-unistyles"
616
+ "solid"
619
617
  ].includes(f));
620
618
  if (unsupportedFrontends && unsupportedFrontends.length > 0) return "none";
621
- const hasReactFrontends = frontend?.some((f) => [
622
- "react-router",
623
- "tanstack-router",
624
- "tanstack-start",
625
- "next"
626
- ].includes(f));
627
- const options = [{
628
- value: "clerk",
629
- label: "Clerk",
630
- hint: "More than auth, Complete User Management"
631
- }];
632
- if (hasReactFrontends) options.unshift({
633
- value: "better-auth",
634
- label: "Better-Auth",
635
- hint: "comprehensive auth framework for TypeScript"
636
- });
637
- options.push({
638
- value: "none",
639
- label: "None",
640
- hint: "No auth"
641
- });
642
619
  const response$1 = await select({
643
620
  message: "Select authentication provider",
644
- options,
645
- initialValue: "none"
621
+ options: [{
622
+ value: "clerk",
623
+ label: "Clerk",
624
+ hint: "More than auth, Complete User Management"
625
+ }, {
626
+ value: "none",
627
+ label: "None"
628
+ }],
629
+ initialValue: "clerk"
646
630
  });
647
631
  if (isCancel(response$1)) return exitCancelled("Operation cancelled");
648
632
  return response$1;
@@ -1385,7 +1369,7 @@ const getLatestCLIVersion = () => {
1385
1369
  */
1386
1370
  function isTelemetryEnabled() {
1387
1371
  const BTS_TELEMETRY_DISABLED = process.env.BTS_TELEMETRY_DISABLED;
1388
- const BTS_TELEMETRY = "0";
1372
+ const BTS_TELEMETRY = "1";
1389
1373
  if (BTS_TELEMETRY_DISABLED !== void 0) return BTS_TELEMETRY_DISABLED !== "1";
1390
1374
  if (BTS_TELEMETRY !== void 0) return BTS_TELEMETRY === "1";
1391
1375
  return true;
@@ -1393,8 +1377,8 @@ function isTelemetryEnabled() {
1393
1377
 
1394
1378
  //#endregion
1395
1379
  //#region src/utils/analytics.ts
1396
- const POSTHOG_API_KEY = "random";
1397
- const POSTHOG_HOST = "random";
1380
+ const POSTHOG_API_KEY = "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs";
1381
+ const POSTHOG_HOST = "https://us.i.posthog.com";
1398
1382
  function generateSessionId() {
1399
1383
  const rand = Math.random().toString(36).slice(2);
1400
1384
  const now = Date.now().toString(36);
@@ -1748,16 +1732,7 @@ function validateConvexConstraints(config, providedFlags) {
1748
1732
  if (has("api") && config.api !== "none") exitWithError("Convex backend requires '--api none'. Please remove the --api flag or set it to 'none'.");
1749
1733
  if (has("dbSetup") && config.dbSetup !== "none") exitWithError("Convex backend requires '--db-setup none'. Please remove the --db-setup flag or set it to 'none'.");
1750
1734
  if (has("serverDeploy") && config.serverDeploy !== "none") exitWithError("Convex backend requires '--server-deploy none'. Please remove the --server-deploy flag or set it to 'none'.");
1751
- if (has("auth") && config.auth === "better-auth") {
1752
- const hasUnsupportedFrontends = config.frontend?.some((f) => [
1753
- "nuxt",
1754
- "svelte",
1755
- "solid",
1756
- "native-nativewind",
1757
- "native-unistyles"
1758
- ].includes(f));
1759
- 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'.");
1760
- }
1735
+ if (has("auth") && config.auth === "better-auth") exitWithError("Better-Auth is not compatible with Convex backend. Please use '--auth clerk' or '--auth none'.");
1761
1736
  }
1762
1737
  function validateBackendNoneConstraints(config, providedFlags) {
1763
1738
  const { backend } = config;
@@ -2004,18 +1979,18 @@ async function updateBtsConfig(projectDir, updates) {
2004
1979
  //#endregion
2005
1980
  //#region src/utils/add-package-deps.ts
2006
1981
  const addPackageDependency = async (opts) => {
2007
- const { dependencies = [], devDependencies = [], customDependencies = {}, customDevDependencies = {}, projectDir } = opts;
1982
+ const { dependencies = [], devDependencies = [], projectDir } = opts;
2008
1983
  const pkgJsonPath = path.join(projectDir, "package.json");
2009
1984
  const pkgJson = await fs.readJson(pkgJsonPath);
2010
1985
  if (!pkgJson.dependencies) pkgJson.dependencies = {};
2011
1986
  if (!pkgJson.devDependencies) pkgJson.devDependencies = {};
2012
1987
  for (const pkgName of dependencies) {
2013
- const version = customDependencies[pkgName] || dependencyVersionMap[pkgName];
1988
+ const version = dependencyVersionMap[pkgName];
2014
1989
  if (version) pkgJson.dependencies[pkgName] = version;
2015
1990
  else console.warn(`Warning: Dependency ${pkgName} not found in version map.`);
2016
1991
  }
2017
1992
  for (const pkgName of devDependencies) {
2018
- const version = customDevDependencies[pkgName] || dependencyVersionMap[pkgName];
1993
+ const version = dependencyVersionMap[pkgName];
2019
1994
  if (version) pkgJson.devDependencies[pkgName] = version;
2020
1995
  else console.warn(`Warning: Dev dependency ${pkgName} not found in version map.`);
2021
1996
  }
@@ -2877,29 +2852,6 @@ async function setupAuthTemplate(projectDir, context) {
2877
2852
  }
2878
2853
  return;
2879
2854
  }
2880
- if (context.backend === "convex" && authProvider === "better-auth") {
2881
- const convexBackendDestDir = path.join(projectDir, "packages/backend");
2882
- const convexBetterAuthBackendSrc = path.join(PKG_ROOT, "templates/auth/better-auth/convex/backend");
2883
- if (await fs.pathExists(convexBetterAuthBackendSrc)) {
2884
- await fs.ensureDir(convexBackendDestDir);
2885
- await processAndCopyFiles("**/*", convexBetterAuthBackendSrc, convexBackendDestDir, context);
2886
- }
2887
- if (webAppDirExists && hasReactWeb) {
2888
- const convexBetterAuthWebBaseSrc = path.join(PKG_ROOT, "templates/auth/better-auth/convex/web/react/base");
2889
- if (await fs.pathExists(convexBetterAuthWebBaseSrc)) await processAndCopyFiles("**/*", convexBetterAuthWebBaseSrc, webAppDir, context);
2890
- const reactFramework = context.frontend.find((f) => [
2891
- "tanstack-router",
2892
- "react-router",
2893
- "tanstack-start",
2894
- "next"
2895
- ].includes(f));
2896
- if (reactFramework) {
2897
- const convexBetterAuthWebSrc = path.join(PKG_ROOT, `templates/auth/better-auth/convex/web/react/${reactFramework}`);
2898
- if (await fs.pathExists(convexBetterAuthWebSrc)) await processAndCopyFiles("**/*", convexBetterAuthWebSrc, webAppDir, context);
2899
- }
2900
- }
2901
- return;
2902
- }
2903
2855
  if (serverAppDirExists && context.backend !== "convex") {
2904
2856
  const authServerBaseSrc = path.join(PKG_ROOT, `templates/auth/${authProvider}/server/base`);
2905
2857
  if (await fs.pathExists(authServerBaseSrc)) await processAndCopyFiles("**/*", authServerBaseSrc, serverAppDir, context);
@@ -4291,35 +4243,6 @@ async function setupAuth(config) {
4291
4243
  projectDir: clientDir
4292
4244
  });
4293
4245
  }
4294
- if (auth === "better-auth") {
4295
- const convexBackendDir = path.join(projectDir, "packages/backend");
4296
- const convexBackendDirExists = await fs.pathExists(convexBackendDir);
4297
- if (convexBackendDirExists) await addPackageDependency({
4298
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4299
- customDependencies: { "better-auth": "1.3.8" },
4300
- projectDir: convexBackendDir
4301
- });
4302
- if (clientDirExists) {
4303
- const hasNextJs = frontend.includes("next");
4304
- const hasTanStackStart = frontend.includes("tanstack-start");
4305
- const hasViteReactOther = frontend.some((f) => ["tanstack-router", "react-router"].includes(f));
4306
- if (hasNextJs) await addPackageDependency({
4307
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4308
- customDependencies: { "better-auth": "1.3.8" },
4309
- projectDir: clientDir
4310
- });
4311
- else if (hasTanStackStart) await addPackageDependency({
4312
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4313
- customDependencies: { "better-auth": "1.3.8" },
4314
- projectDir: clientDir
4315
- });
4316
- else if (hasViteReactOther) await addPackageDependency({
4317
- dependencies: ["better-auth", "@convex-dev/better-auth"],
4318
- customDependencies: { "better-auth": "1.3.8" },
4319
- projectDir: clientDir
4320
- });
4321
- }
4322
- }
4323
4246
  const hasNativeWind = frontend.includes("native-nativewind");
4324
4247
  const hasUnistyles = frontend.includes("native-unistyles");
4325
4248
  if (auth === "clerk" && nativeDirExists && (hasNativeWind || hasUnistyles)) await addPackageDependency({
@@ -4477,18 +4400,6 @@ async function setupEnvironmentVariables(config) {
4477
4400
  });
4478
4401
  }
4479
4402
  }
4480
- if (backend === "convex" && auth === "better-auth") {
4481
- if (hasNextJs) clientVars.push({
4482
- key: "NEXT_PUBLIC_CONVEX_SITE_URL",
4483
- value: "https://<YOUR_CONVEX_URL>",
4484
- condition: true
4485
- });
4486
- else if (hasReactRouter || hasTanStackRouter || hasTanStackStart) clientVars.push({
4487
- key: "VITE_CONVEX_SITE_URL",
4488
- value: "https://<YOUR_CONVEX_URL>",
4489
- condition: true
4490
- });
4491
- }
4492
4403
  await addEnvVariablesToFile(path.join(clientDir, ".env"), clientVars);
4493
4404
  }
4494
4405
  }
@@ -4514,24 +4425,7 @@ async function setupEnvironmentVariables(config) {
4514
4425
  await addEnvVariablesToFile(path.join(nativeDir, ".env"), nativeVars);
4515
4426
  }
4516
4427
  }
4517
- if (backend === "convex") {
4518
- if (auth === "better-auth") {
4519
- const convexBackendDir = path.join(projectDir, "packages/backend");
4520
- if (await fs.pathExists(convexBackendDir)) {
4521
- const convexBackendVars = [{
4522
- key: hasTanStackStart ? "NEXT_PUBLIC_CONVEX_SITE_URL" : "VITE_CONVEX_SITE_URL",
4523
- value: "",
4524
- condition: true
4525
- }, {
4526
- key: "SITE_URL",
4527
- value: "http://localhost:3001",
4528
- condition: true
4529
- }];
4530
- await addEnvVariablesToFile(path.join(convexBackendDir, ".env.local"), convexBackendVars);
4531
- }
4532
- }
4533
- return;
4534
- }
4428
+ if (backend === "convex") return;
4535
4429
  const serverDir = path.join(projectDir, "apps/server");
4536
4430
  if (!await fs.pathExists(serverDir)) return;
4537
4431
  const envPath = path.join(serverDir, ".env");
@@ -5816,6 +5710,17 @@ async function setupNodeRuntime(serverDir, backend) {
5816
5710
  });
5817
5711
  }
5818
5712
 
5713
+ //#endregion
5714
+ //#region src/helpers/core/convex-codegen.ts
5715
+ async function runConvexCodegen(projectDir, packageManager) {
5716
+ const backendDir = path.join(projectDir, "packages/backend");
5717
+ const cmd = getPackageExecutionCommand(packageManager, "convex codegen");
5718
+ await execa(cmd, {
5719
+ cwd: backendDir,
5720
+ shell: true
5721
+ });
5722
+ }
5723
+
5819
5724
  //#endregion
5820
5725
  //#region src/helpers/core/create-readme.ts
5821
5726
  async function createReadme(projectDir, options) {
@@ -6607,6 +6512,7 @@ async function createProject(options, cliInput) {
6607
6512
  await setupServerDeploy(options);
6608
6513
  await createReadme(projectDir, options);
6609
6514
  await writeBtsConfig(options);
6515
+ if (isConvex) await runConvexCodegen(projectDir, options.packageManager);
6610
6516
  log.success("Project template successfully scaffolded!");
6611
6517
  if (options.install) await installDependencies({
6612
6518
  projectDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "2.46.0-canary.c8dd04fa",
3
+ "version": "2.46.1",
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",
@@ -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
+ }
@@ -54,7 +54,7 @@ app.use(
54
54
  );
55
55
 
56
56
  {{#if (eq auth "better-auth")}}
57
- app.on(["POST", "GET"], "/api/auth/**", (c) => auth.handler(c.req.raw));
57
+ app.on(["POST", "GET"], "/api/auth/*", (c) => auth.handler(c.req.raw));
58
58
  {{/if}}
59
59
 
60
60
  {{#if (eq api "orpc")}}
@@ -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
- }