@better-t-stack/template-generator 3.26.1 → 3.27.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.
package/dist/index.mjs CHANGED
@@ -388,7 +388,7 @@ function updatePackageJsonsWithCatalogs(vfs, packagesInfo, catalog) {
388
388
  //#endregion
389
389
  //#region src/utils/db-scripts.ts
390
390
  function getDbScriptSupport(config) {
391
- const isD1Alchemy = config.dbSetup === "d1" && config.serverDeploy === "cloudflare";
391
+ const isD1Alchemy = config.dbSetup === "d1" && (config.serverDeploy === "cloudflare" || config.backend === "self" && config.webDeploy === "cloudflare");
392
392
  if (!(config.backend !== "convex" && config.backend !== "none" && config.database !== "none" && config.orm !== "none" && config.orm !== "mongoose")) return {
393
393
  hasDbScripts: false,
394
394
  hasDbPush: false,
@@ -713,7 +713,7 @@ const dependencyVersionMap = {
713
713
  "@clerk/nextjs": "^7.0.5",
714
714
  "@clerk/react": "^6.1.1",
715
715
  "@clerk/react-router": "^3.0.5",
716
- "@clerk/tanstack-react-start": "^1.0.5",
716
+ "@clerk/tanstack-react-start": "^1.1.3",
717
717
  "@clerk/expo": "^3.1.3",
718
718
  "drizzle-orm": "^0.45.1",
719
719
  "drizzle-kit": "^0.31.8",
@@ -726,18 +726,18 @@ const dependencyVersionMap = {
726
726
  "@types/ws": "^8.18.1",
727
727
  ws: "^8.18.3",
728
728
  mysql2: "^3.14.0",
729
- "@prisma/client": "^7.2.0",
730
- prisma: "^7.2.0",
731
- "@prisma/adapter-d1": "^7.2.0",
732
- "@prisma/adapter-neon": "^7.2.0",
733
- "@prisma/adapter-mariadb": "^7.2.0",
734
- "@prisma/adapter-libsql": "^7.2.0",
735
- "@prisma/adapter-better-sqlite3": "^7.2.0",
736
- "@prisma/adapter-pg": "^7.2.0",
737
- "@prisma/adapter-planetscale": "^7.2.0",
729
+ "@prisma/client": "^7.7.0",
730
+ prisma: "^7.7.0",
731
+ "@prisma/adapter-d1": "^7.7.0",
732
+ "@prisma/adapter-neon": "^7.7.0",
733
+ "@prisma/adapter-mariadb": "^7.7.0",
734
+ "@prisma/adapter-libsql": "^7.7.0",
735
+ "@prisma/adapter-better-sqlite3": "^7.7.0",
736
+ "@prisma/adapter-pg": "^7.7.0",
737
+ "@prisma/adapter-planetscale": "^7.7.0",
738
738
  mongoose: "^8.14.0",
739
- "vite-plugin-pwa": "^1.0.1",
740
- "@vite-pwa/assets-generator": "^1.0.0",
739
+ "vite-plugin-pwa": "^1.2.0",
740
+ "@vite-pwa/assets-generator": "^1.0.2",
741
741
  "@tauri-apps/cli": "^2.4.0",
742
742
  "@biomejs/biome": "^2.2.0",
743
743
  oxlint: "^1.41.0",
@@ -771,14 +771,14 @@ const dependencyVersionMap = {
771
771
  "@ai-sdk/devtools": "^0.0.2",
772
772
  streamdown: "^1.6.10",
773
773
  shiki: "^3.20.0",
774
- "@orpc/server": "^1.12.2",
775
- "@orpc/client": "^1.12.2",
776
- "@orpc/openapi": "^1.12.2",
777
- "@orpc/zod": "^1.12.2",
778
- "@orpc/tanstack-query": "^1.13.6",
779
- "@trpc/tanstack-react-query": "^11.13.4",
780
- "@trpc/server": "^11.13.4",
781
- "@trpc/client": "^11.13.4",
774
+ "@orpc/server": "^1.13.14",
775
+ "@orpc/client": "^1.13.14",
776
+ "@orpc/openapi": "^1.13.14",
777
+ "@orpc/zod": "^1.13.14",
778
+ "@orpc/tanstack-query": "^1.13.14",
779
+ "@trpc/tanstack-react-query": "^11.16.0",
780
+ "@trpc/server": "^11.16.0",
781
+ "@trpc/client": "^11.16.0",
782
782
  next: "^16.2.0",
783
783
  convex: "^1.33.1",
784
784
  "@convex-dev/react-query": "^0.1.0",
@@ -786,7 +786,7 @@ const dependencyVersionMap = {
786
786
  "convex-svelte": "^0.0.12",
787
787
  "convex-nuxt": "0.1.5",
788
788
  "convex-vue": "^0.1.5",
789
- "@convex-dev/better-auth": "^0.11.3",
789
+ "@convex-dev/better-auth": "^0.11.4",
790
790
  "@tanstack/svelte-query": "^5.85.3",
791
791
  "@tanstack/svelte-query-devtools": "^5.85.3",
792
792
  "@tanstack/vue-query-devtools": "^6.1.5",
@@ -794,21 +794,21 @@ const dependencyVersionMap = {
794
794
  "@tanstack/react-query-devtools": "^5.91.1",
795
795
  "@tanstack/react-query": "^5.90.12",
796
796
  "@tanstack/react-form": "^1.28.0",
797
- "@tanstack/react-router-ssr-query": "^1.142.7",
797
+ "@tanstack/react-router-ssr-query": "^1.166.11",
798
798
  "@tanstack/solid-form": "^1.28.0",
799
799
  "@tanstack/svelte-form": "^1.28.0",
800
- "@tanstack/solid-query": "^5.87.4",
801
- "@tanstack/solid-query-devtools": "^5.87.4",
802
- "@tanstack/solid-router-devtools": "^1.131.44",
803
- wrangler: "^4.54.0",
800
+ "@tanstack/solid-query": "^5.99.1",
801
+ "@tanstack/solid-query-devtools": "^5.99.1",
802
+ "@tanstack/solid-router-devtools": "^1.166.13",
803
+ wrangler: "^4.77.0",
804
804
  "@cloudflare/vite-plugin": "^1.17.1",
805
- "@opennextjs/cloudflare": "^1.14.6",
805
+ "@opennextjs/cloudflare": "^1.17.3",
806
806
  "nitro-cloudflare-dev": "^0.2.2",
807
- "@sveltejs/adapter-cloudflare": "^7.2.4",
807
+ "@sveltejs/adapter-cloudflare": "^7.2.8",
808
808
  "@cloudflare/workers-types": "^4.20251213.0",
809
809
  "@astrojs/cloudflare": "^13.0.1",
810
810
  "@astrojs/node": "^10.0.0-beta.9",
811
- alchemy: "^0.87.0",
811
+ alchemy: "^0.91.2",
812
812
  dotenv: "^17.2.2",
813
813
  tsdown: "^0.16.5",
814
814
  zod: "^4.1.13",
@@ -1121,7 +1121,7 @@ function processApiDeps(vfs, config) {
1121
1121
  addApiPackageDeps(vfs, api, backend, frontend, auth);
1122
1122
  addServerDeps(vfs, api, backend);
1123
1123
  addSelfBackendWebDeps(vfs, api, backend, frontendType);
1124
- addWebClientDeps(vfs, api, backend, frontendType);
1124
+ addWebClientDeps(vfs, api, backend, frontend, frontendType);
1125
1125
  if (frontendType.hasNative) addNativeDeps(vfs, api, backend);
1126
1126
  addQueryDeps(vfs, frontend, backend);
1127
1127
  }
@@ -1209,28 +1209,34 @@ function addSelfBackendWebDeps(vfs, api, backend, _frontendType) {
1209
1209
  ]
1210
1210
  });
1211
1211
  }
1212
- function addWebClientDeps(vfs, api, backend, frontendType) {
1212
+ function addWebClientDeps(vfs, api, backend, frontend, frontendType) {
1213
1213
  const webPath = "apps/web/package.json";
1214
1214
  if (!vfs.exists(webPath) || backend === "convex") return;
1215
- if (api === "trpc" && frontendType.hasReactWeb) addPackageDependency({
1216
- vfs,
1217
- packagePath: webPath,
1218
- dependencies: [
1215
+ if (api === "trpc" && frontendType.hasReactWeb) {
1216
+ const deps = [
1219
1217
  "@trpc/tanstack-react-query",
1220
1218
  "@trpc/client",
1221
1219
  "@trpc/server"
1222
- ]
1223
- });
1224
- else if (api === "orpc" && frontendType.hasReactWeb) addPackageDependency({
1225
- vfs,
1226
- packagePath: webPath,
1227
- dependencies: [
1220
+ ];
1221
+ if (frontend.includes("tanstack-start")) deps.push("@tanstack/react-router-ssr-query");
1222
+ addPackageDependency({
1223
+ vfs,
1224
+ packagePath: webPath,
1225
+ dependencies: deps
1226
+ });
1227
+ } else if (api === "orpc" && frontendType.hasReactWeb) {
1228
+ const deps = [
1228
1229
  "@orpc/tanstack-query",
1229
1230
  "@orpc/client",
1230
1231
  "@orpc/server"
1231
- ]
1232
- });
1233
- else if (api === "orpc" && frontendType.hasNuxtWeb) addPackageDependency({
1232
+ ];
1233
+ if (frontend.includes("tanstack-start")) deps.push("@tanstack/react-router-ssr-query");
1234
+ addPackageDependency({
1235
+ vfs,
1236
+ packagePath: webPath,
1237
+ dependencies: deps
1238
+ });
1239
+ } else if (api === "orpc" && frontendType.hasNuxtWeb) addPackageDependency({
1234
1240
  vfs,
1235
1241
  packagePath: webPath,
1236
1242
  dependencies: [
@@ -1632,7 +1638,10 @@ function processAuthPlugins(vfs, config) {
1632
1638
  namedImports: [named]
1633
1639
  });
1634
1640
  });
1635
- const betterAuthCall = sourceFile.getVariableDeclaration("auth")?.getInitializerIfKind(SyntaxKind.CallExpression);
1641
+ const betterAuthCall = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).find((callExpression) => {
1642
+ const expression = callExpression.getExpression();
1643
+ return Node.isIdentifier(expression) && expression.getText() === "betterAuth";
1644
+ });
1636
1645
  if (betterAuthCall) {
1637
1646
  const configObject = betterAuthCall.getArguments()[0]?.asKind(SyntaxKind.ObjectLiteralExpression);
1638
1647
  if (configObject) {
@@ -1877,7 +1886,7 @@ function processDeployDeps(vfs, config) {
1877
1886
  function processEnvDeps(vfs, config) {
1878
1887
  const envPath = "packages/env/package.json";
1879
1888
  if (!vfs.exists(envPath)) return;
1880
- const { frontend, backend, runtime } = config;
1889
+ const { frontend, backend, runtime, webDeploy } = config;
1881
1890
  const deps = ["zod"];
1882
1891
  const hasNative = frontend.some((value) => [
1883
1892
  "native-bare",
@@ -1890,6 +1899,7 @@ function processEnvDeps(vfs, config) {
1890
1899
  else if (hasNuxt) deps.push("@t3-oss/env-nuxt");
1891
1900
  if (hasNative || !hasNextJs && !hasNuxt) deps.push("@t3-oss/env-core");
1892
1901
  if (backend !== "convex" && backend !== "none" && runtime !== "workers" && !deps.includes("@t3-oss/env-core")) deps.push("@t3-oss/env-core");
1902
+ if (backend === "self" && webDeploy === "cloudflare" && hasNextJs) deps.push("@opennextjs/cloudflare");
1893
1903
  addPackageDependency({
1894
1904
  vfs,
1895
1905
  packagePath: envPath,
@@ -2058,7 +2068,7 @@ function buildConvexBackendVars(frontend, auth, examples) {
2058
2068
  const hasNextJs = frontend.includes("next");
2059
2069
  const hasNative = frontend.includes("native-bare") || frontend.includes("native-uniwind") || frontend.includes("native-unistyles");
2060
2070
  const hasWeb = frontend.includes("react-router") || frontend.includes("tanstack-router") || frontend.includes("tanstack-start") || hasNextJs || frontend.includes("nuxt") || frontend.includes("solid") || frontend.includes("svelte") || frontend.includes("astro");
2061
- const defaultSiteUrl = hasNative && !hasWeb ? "http://localhost:8081" : frontend.includes("react-router") || frontend.includes("tanstack-router") || frontend.includes("svelte") ? "http://localhost:5173" : frontend.includes("astro") ? "http://localhost:4321" : "http://localhost:3001";
2071
+ const defaultSiteUrl = hasNative && !hasWeb ? "http://localhost:8081" : frontend.includes("react-router") || frontend.includes("svelte") ? "http://localhost:5173" : frontend.includes("astro") ? "http://localhost:4321" : "http://localhost:3001";
2062
2072
  const vars = [];
2063
2073
  if (examples?.includes("ai")) vars.push({
2064
2074
  key: "GOOGLE_GENERATIVE_AI_API_KEY",
@@ -2096,7 +2106,7 @@ function buildConvexBackendVars(frontend, auth, examples) {
2096
2106
  function buildConvexCommentBlocks(frontend, auth, examples) {
2097
2107
  const hasNative = frontend.includes("native-bare") || frontend.includes("native-uniwind") || frontend.includes("native-unistyles");
2098
2108
  const hasWeb = frontend.includes("react-router") || frontend.includes("tanstack-router") || frontend.includes("tanstack-start") || frontend.includes("next") || frontend.includes("nuxt") || frontend.includes("solid") || frontend.includes("svelte") || frontend.includes("astro");
2099
- const defaultSiteUrl = hasNative && !hasWeb ? "http://localhost:8081" : frontend.includes("react-router") || frontend.includes("tanstack-router") || frontend.includes("svelte") ? "http://localhost:5173" : frontend.includes("astro") ? "http://localhost:4321" : "http://localhost:3001";
2109
+ const defaultSiteUrl = hasNative && !hasWeb ? "http://localhost:8081" : frontend.includes("react-router") || frontend.includes("svelte") ? "http://localhost:5173" : frontend.includes("astro") ? "http://localhost:4321" : "http://localhost:3001";
2100
2110
  let commentBlocks = "";
2101
2111
  if (examples?.includes("ai")) commentBlocks += `# Set Google AI API key for AI agent
2102
2112
  # npx convex env set GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key
@@ -2109,13 +2119,11 @@ ${hasWeb || hasNative ? `# npx convex env set SITE_URL ${defaultSiteUrl}\n` : ""
2109
2119
  }
2110
2120
  function buildServerVars(backend, frontend, auth, api, database, dbSetup, runtime, webDeploy, serverDeploy, payments, examples) {
2111
2121
  const hasReactRouter = frontend.includes("react-router");
2112
- const hasTanStackRouter = frontend.includes("tanstack-router");
2113
2122
  const hasSvelte = frontend.includes("svelte");
2114
2123
  const hasAstro = frontend.includes("astro");
2115
2124
  let corsOrigin = "http://localhost:3001";
2116
2125
  if (hasAstro) corsOrigin = "http://localhost:4321";
2117
- else if (hasReactRouter || hasTanStackRouter || hasSvelte) corsOrigin = "http://localhost:5173";
2118
- else if (backend === "self") corsOrigin = "http://localhost:3001";
2126
+ else if (hasReactRouter || hasSvelte) corsOrigin = "http://localhost:5173";
2119
2127
  let databaseUrl = null;
2120
2128
  if (database !== "none" && dbSetup === "none") switch (database) {
2121
2129
  case "postgres":
@@ -4523,12 +4531,16 @@ async function authenticateClerkRequest(request: Request): Promise<ClerkContextA
4523
4531
  {{#if (and (eq backend 'self') (includes frontend "next"))}}
4524
4532
  import type { NextRequest } from "next/server";
4525
4533
  {{#if (eq auth "better-auth")}}
4534
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
4535
+ import { createAuth } from "@{{projectName}}/auth";
4536
+ {{else}}
4526
4537
  import { auth } from "@{{projectName}}/auth";
4527
4538
  {{/if}}
4539
+ {{/if}}
4528
4540
 
4529
4541
  export async function createContext(req: NextRequest){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
4530
4542
  {{#if (eq auth "better-auth")}}
4531
- const session = await auth.api.getSession({
4543
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
4532
4544
  headers: req.headers,
4533
4545
  });
4534
4546
  return {
@@ -4551,12 +4563,16 @@ export async function createContext(req: NextRequest){{#if (eq auth "clerk")}}:
4551
4563
 
4552
4564
  {{else if (and (eq backend 'self') (includes frontend "tanstack-start"))}}
4553
4565
  {{#if (eq auth "better-auth")}}
4566
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
4567
+ import { createAuth } from "@{{projectName}}/auth";
4568
+ {{else}}
4554
4569
  import { auth } from "@{{projectName}}/auth";
4555
4570
  {{/if}}
4571
+ {{/if}}
4556
4572
 
4557
4573
  export async function createContext({ req }: { req: Request }){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
4558
4574
  {{#if (eq auth "better-auth")}}
4559
- const session = await auth.api.getSession({
4575
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
4560
4576
  headers: req.headers,
4561
4577
  });
4562
4578
  return {
@@ -4579,8 +4595,12 @@ export async function createContext({ req }: { req: Request }){{#if (eq auth "cl
4579
4595
 
4580
4596
  {{else if (and (eq backend 'self') (includes frontend "nuxt"))}}
4581
4597
  {{#if (eq auth "better-auth")}}
4598
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
4599
+ import { createAuth } from "@{{projectName}}/auth";
4600
+ {{else}}
4582
4601
  import { auth } from "@{{projectName}}/auth";
4583
4602
  {{/if}}
4603
+ {{/if}}
4584
4604
 
4585
4605
  export type CreateContextOptions = {
4586
4606
  headers: Headers;
@@ -4588,7 +4608,7 @@ export type CreateContextOptions = {
4588
4608
 
4589
4609
  export async function createContext({ headers }: CreateContextOptions) {
4590
4610
  {{#if (eq auth "better-auth")}}
4591
- const session = await auth.api.getSession({ headers });
4611
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({ headers });
4592
4612
  return {
4593
4613
  auth: null,
4594
4614
  session,
@@ -4603,8 +4623,12 @@ export async function createContext({ headers }: CreateContextOptions) {
4603
4623
 
4604
4624
  {{else if (and (eq backend 'self') (includes frontend "astro"))}}
4605
4625
  {{#if (eq auth "better-auth")}}
4626
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
4627
+ import { createAuth } from "@{{projectName}}/auth";
4628
+ {{else}}
4606
4629
  import { auth } from "@{{projectName}}/auth";
4607
4630
  {{/if}}
4631
+ {{/if}}
4608
4632
 
4609
4633
  export type CreateContextOptions = {
4610
4634
  headers: Headers;
@@ -4612,7 +4636,7 @@ export type CreateContextOptions = {
4612
4636
 
4613
4637
  export async function createContext({ headers }: CreateContextOptions) {
4614
4638
  {{#if (eq auth "better-auth")}}
4615
- const session = await auth.api.getSession({ headers });
4639
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({ headers });
4616
4640
  return {
4617
4641
  auth: null,
4618
4642
  session,
@@ -4628,8 +4652,12 @@ export async function createContext({ headers }: CreateContextOptions) {
4628
4652
  {{else if (eq backend 'hono')}}
4629
4653
  import type { Context as HonoContext } from "hono";
4630
4654
  {{#if (eq auth "better-auth")}}
4655
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
4656
+ import { createAuth } from "@{{projectName}}/auth";
4657
+ {{else}}
4631
4658
  import { auth } from "@{{projectName}}/auth";
4632
4659
  {{/if}}
4660
+ {{/if}}
4633
4661
 
4634
4662
  export type CreateContextOptions = {
4635
4663
  context: HonoContext;
@@ -4637,7 +4665,7 @@ export type CreateContextOptions = {
4637
4665
 
4638
4666
  export async function createContext({ context }: CreateContextOptions){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
4639
4667
  {{#if (eq auth "better-auth")}}
4640
- const session = await auth.api.getSession({
4668
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
4641
4669
  headers: context.req.raw.headers,
4642
4670
  });
4643
4671
  return {
@@ -5371,12 +5399,16 @@ async function authenticateClerkRequest(request: Request): Promise<ClerkContextA
5371
5399
  {{#if (and (eq backend 'self') (includes frontend "next"))}}
5372
5400
  import type { NextRequest } from "next/server";
5373
5401
  {{#if (eq auth "better-auth")}}
5402
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
5403
+ import { createAuth } from "@{{projectName}}/auth";
5404
+ {{else}}
5374
5405
  import { auth } from "@{{projectName}}/auth";
5375
5406
  {{/if}}
5407
+ {{/if}}
5376
5408
 
5377
5409
  export async function createContext(req: NextRequest){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
5378
5410
  {{#if (eq auth "better-auth")}}
5379
- const session = await auth.api.getSession({
5411
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
5380
5412
  headers: req.headers,
5381
5413
  });
5382
5414
  return {
@@ -5399,12 +5431,16 @@ export async function createContext(req: NextRequest){{#if (eq auth "clerk")}}:
5399
5431
 
5400
5432
  {{else if (and (eq backend 'self') (includes frontend "tanstack-start"))}}
5401
5433
  {{#if (eq auth "better-auth")}}
5434
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
5435
+ import { createAuth } from "@{{projectName}}/auth";
5436
+ {{else}}
5402
5437
  import { auth } from "@{{projectName}}/auth";
5403
5438
  {{/if}}
5439
+ {{/if}}
5404
5440
 
5405
5441
  export async function createContext({ req }: { req: Request }){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
5406
5442
  {{#if (eq auth "better-auth")}}
5407
- const session = await auth.api.getSession({
5443
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
5408
5444
  headers: req.headers,
5409
5445
  });
5410
5446
  return {
@@ -5428,8 +5464,12 @@ export async function createContext({ req }: { req: Request }){{#if (eq auth "cl
5428
5464
  {{else if (eq backend 'hono')}}
5429
5465
  import type { Context as HonoContext } from "hono";
5430
5466
  {{#if (eq auth "better-auth")}}
5467
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
5468
+ import { createAuth } from "@{{projectName}}/auth";
5469
+ {{else}}
5431
5470
  import { auth } from "@{{projectName}}/auth";
5432
5471
  {{/if}}
5472
+ {{/if}}
5433
5473
 
5434
5474
  export type CreateContextOptions = {
5435
5475
  context: HonoContext;
@@ -5437,7 +5477,7 @@ export type CreateContextOptions = {
5437
5477
 
5438
5478
  export async function createContext({ context }: CreateContextOptions){{#if (eq auth "clerk")}}: Promise<ClerkRequestContext>{{/if}} {
5439
5479
  {{#if (eq auth "better-auth")}}
5440
- const session = await auth.api.getSession({
5480
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
5441
5481
  headers: context.req.raw.headers,
5442
5482
  });
5443
5483
  return {
@@ -8834,10 +8874,17 @@ declare namespace App {
8834
8874
  }
8835
8875
  }
8836
8876
  `],
8837
- ["auth/better-auth/fullstack/astro/src/middleware.ts.hbs", `import { auth } from "@{{projectName}}/auth";
8877
+ ["auth/better-auth/fullstack/astro/src/middleware.ts.hbs", `{{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8878
+ import { createAuth } from "@{{projectName}}/auth";
8879
+ {{else}}
8880
+ import { auth } from "@{{projectName}}/auth";
8881
+ {{/if}}
8838
8882
  import { defineMiddleware } from "astro:middleware";
8839
8883
 
8840
8884
  export const onRequest = defineMiddleware(async (context, next) => {
8885
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8886
+ const auth = createAuth();
8887
+ {{/if}}
8841
8888
  const isAuthed = await auth.api.getSession({
8842
8889
  headers: context.request.headers,
8843
8890
  });
@@ -8853,34 +8900,72 @@ export const onRequest = defineMiddleware(async (context, next) => {
8853
8900
  return next();
8854
8901
  });
8855
8902
  `],
8856
- ["auth/better-auth/fullstack/astro/src/pages/api/auth/[...all].ts.hbs", `import { auth } from "@{{projectName}}/auth";
8903
+ ["auth/better-auth/fullstack/astro/src/pages/api/auth/[...all].ts.hbs", `{{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8904
+ import { createAuth } from "@{{projectName}}/auth";
8905
+ {{else}}
8906
+ import { auth } from "@{{projectName}}/auth";
8907
+ {{/if}}
8857
8908
  import type { APIRoute } from "astro";
8858
8909
 
8859
8910
  export const ALL: APIRoute = async (ctx) => {
8911
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8912
+ const auth = createAuth();
8913
+ {{/if}}
8860
8914
  return auth.handler(ctx.request);
8861
8915
  };
8862
8916
  `],
8863
- ["auth/better-auth/fullstack/next/src/app/api/auth/[...all]/route.ts.hbs", `import { auth } from "@{{projectName}}/auth";
8917
+ ["auth/better-auth/fullstack/next/src/app/api/auth/[...all]/route.ts.hbs", `{{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8918
+ import { createAuth } from "@{{projectName}}/auth";
8919
+ {{else}}
8920
+ import { auth } from "@{{projectName}}/auth";
8921
+ {{/if}}
8864
8922
  import { toNextJsHandler } from "better-auth/next-js";
8865
8923
 
8866
- export const { GET, POST } = toNextJsHandler(auth.handler);
8924
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8925
+ export async function GET(request: Request) {
8926
+ return toNextJsHandler(createAuth()).GET(request);
8927
+ }
8928
+
8929
+ export async function POST(request: Request) {
8930
+ return toNextJsHandler(createAuth()).POST(request);
8931
+ }
8932
+ {{else}}
8933
+ export const { GET, POST } = toNextJsHandler(auth);
8934
+ {{/if}}
8867
8935
  `],
8868
- ["auth/better-auth/fullstack/nuxt/server/api/auth/[...all].ts.hbs", `import { auth } from "@{{projectName}}/auth";
8936
+ ["auth/better-auth/fullstack/nuxt/server/api/auth/[...all].ts.hbs", `{{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8937
+ import { createAuth } from "@{{projectName}}/auth";
8938
+ {{else}}
8939
+ import { auth } from "@{{projectName}}/auth";
8940
+ {{/if}}
8869
8941
 
8870
8942
  export default defineEventHandler((event) => {
8943
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8944
+ const auth = createAuth();
8945
+ {{/if}}
8871
8946
  return auth.handler(toWebRequest(event));
8872
8947
  });
8873
8948
  `],
8874
- ["auth/better-auth/fullstack/tanstack-start/src/routes/api/auth/$.ts.hbs", `import { auth } from '@{{projectName}}/auth'
8949
+ ["auth/better-auth/fullstack/tanstack-start/src/routes/api/auth/$.ts.hbs", `{{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8950
+ import { createAuth } from '@{{projectName}}/auth'
8951
+ {{else}}
8952
+ import { auth } from '@{{projectName}}/auth'
8953
+ {{/if}}
8875
8954
  import { createFileRoute } from '@tanstack/react-router'
8876
8955
 
8877
8956
  export const Route = createFileRoute('/api/auth/$')({
8878
8957
  server: {
8879
8958
  handlers: {
8880
8959
  GET: ({ request }) => {
8960
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8961
+ const auth = createAuth()
8962
+ {{/if}}
8881
8963
  return auth.handler(request)
8882
8964
  },
8883
8965
  POST: ({ request }) => {
8966
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
8967
+ const auth = createAuth()
8968
+ {{/if}}
8884
8969
  return auth.handler(request)
8885
8970
  },
8886
8971
  },
@@ -10800,67 +10885,75 @@ import { env } from "@{{projectName}}/env/server";
10800
10885
  import { polar, checkout, portal } from "@polar-sh/better-auth";
10801
10886
  import { polarClient } from "./lib/payments";
10802
10887
  {{/if}}
10803
- import prisma from "@{{projectName}}/db";
10888
+ import { createPrismaClient } from "@{{projectName}}/db";
10804
10889
 
10805
- export const auth = betterAuth({
10806
- database: prismaAdapter(prisma, {
10890
+ export function createAuth() {
10891
+ const prisma = createPrismaClient();
10892
+
10893
+ return betterAuth({
10894
+ database: prismaAdapter(prisma, {
10807
10895
  {{#if (eq database "postgres")}}provider: "postgresql",{{/if}}
10808
10896
  {{#if (eq database "sqlite")}}provider: "sqlite",{{/if}}
10809
10897
  {{#if (eq database "mysql")}}provider: "mysql",{{/if}}
10810
10898
  {{#if (eq database "mongodb")}}provider: "mongodb",{{/if}}
10811
- }),
10899
+ }),
10812
10900
 
10813
- trustedOrigins: [
10814
- env.CORS_ORIGIN,
10901
+ trustedOrigins: [
10902
+ env.CORS_ORIGIN,
10815
10903
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
10816
- "{{projectName}}://",
10817
- ...(env.NODE_ENV === "development"
10818
- ? [
10819
- "exp://",
10820
- "exp://**",
10821
- "exp://192.168.*.*:*/**",
10822
- "http://localhost:8081",
10823
- ]
10824
- : []),
10904
+ "{{projectName}}://",
10905
+ ...(env.NODE_ENV === "development"
10906
+ ? [
10907
+ "exp://",
10908
+ "exp://**",
10909
+ "exp://192.168.*.*:*/**",
10910
+ "http://localhost:8081",
10911
+ ]
10912
+ : []),
10825
10913
  {{/if}}
10826
- ],
10827
- emailAndPassword: {
10828
- enabled: true,
10829
- },
10830
- secret: env.BETTER_AUTH_SECRET,
10831
- baseURL: env.BETTER_AUTH_URL,
10914
+ ],
10915
+ emailAndPassword: {
10916
+ enabled: true,
10917
+ },
10918
+ secret: env.BETTER_AUTH_SECRET,
10919
+ baseURL: env.BETTER_AUTH_URL,
10832
10920
  {{#if (ne backend "self")}}
10833
- advanced: {
10834
- defaultCookieAttributes: {
10835
- sameSite: "none",
10836
- secure: true,
10837
- httpOnly: true,
10921
+ advanced: {
10922
+ defaultCookieAttributes: {
10923
+ sameSite: "none",
10924
+ secure: true,
10925
+ httpOnly: true,
10926
+ },
10838
10927
  },
10839
- },
10840
10928
  {{/if}}
10841
- plugins: [
10929
+ plugins: [
10842
10930
  {{#if (eq payments "polar")}}
10843
- polar({
10844
- client: polarClient,
10845
- createCustomerOnSignUp: true,
10846
- enableCustomerPortal: true,
10847
- use: [
10848
- checkout({
10849
- products: [
10850
- {
10851
- productId: "your-product-id",
10852
- slug: "pro",
10853
- },
10854
- ],
10855
- successUrl: env.POLAR_SUCCESS_URL,
10856
- authenticatedUsersOnly: true,
10857
- }),
10858
- portal(),
10859
- ],
10860
- }),
10931
+ polar({
10932
+ client: polarClient,
10933
+ createCustomerOnSignUp: true,
10934
+ enableCustomerPortal: true,
10935
+ use: [
10936
+ checkout({
10937
+ products: [
10938
+ {
10939
+ productId: "your-product-id",
10940
+ slug: "pro",
10941
+ },
10942
+ ],
10943
+ successUrl: env.POLAR_SUCCESS_URL,
10944
+ authenticatedUsersOnly: true,
10945
+ }),
10946
+ portal(),
10947
+ ],
10948
+ }),
10949
+ {{/if}}
10950
+ ],
10951
+ });
10952
+ }
10953
+
10954
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
10955
+ export const auth = createAuth();
10861
10956
  {{/if}}
10862
- ],
10863
- });
10864
10957
  {{/if}}
10865
10958
 
10866
10959
  {{#if (eq orm "drizzle")}}
@@ -10872,68 +10965,76 @@ import { env } from "@{{projectName}}/env/server";
10872
10965
  import { polar, checkout, portal } from "@polar-sh/better-auth";
10873
10966
  import { polarClient } from "./lib/payments";
10874
10967
  {{/if}}
10875
- import { db } from "@{{projectName}}/db";
10968
+ import { createDb } from "@{{projectName}}/db";
10876
10969
  import * as schema from "@{{projectName}}/db/schema/auth";
10877
10970
 
10878
10971
 
10879
- export const auth = betterAuth({
10880
- database: drizzleAdapter(db, {
10972
+ export function createAuth() {
10973
+ const db = createDb();
10974
+
10975
+ return betterAuth({
10976
+ database: drizzleAdapter(db, {
10881
10977
  {{#if (eq database "postgres")}}provider: "pg",{{/if}}
10882
10978
  {{#if (eq database "sqlite")}}provider: "sqlite",{{/if}}
10883
10979
  {{#if (eq database "mysql")}}provider: "mysql",{{/if}}
10884
- schema: schema,
10885
- }),
10886
- trustedOrigins: [
10887
- env.CORS_ORIGIN,
10980
+ schema: schema,
10981
+ }),
10982
+ trustedOrigins: [
10983
+ env.CORS_ORIGIN,
10888
10984
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
10889
- "{{projectName}}://",
10890
- ...(env.NODE_ENV === "development"
10891
- ? [
10892
- "exp://",
10893
- "exp://**",
10894
- "exp://192.168.*.*:*/**",
10895
- "http://localhost:8081",
10896
- ]
10897
- : []),
10985
+ "{{projectName}}://",
10986
+ ...(env.NODE_ENV === "development"
10987
+ ? [
10988
+ "exp://",
10989
+ "exp://**",
10990
+ "exp://192.168.*.*:*/**",
10991
+ "http://localhost:8081",
10992
+ ]
10993
+ : []),
10898
10994
  {{/if}}
10899
- ],
10900
- emailAndPassword: {
10901
- enabled: true,
10902
- },
10903
- secret: env.BETTER_AUTH_SECRET,
10904
- baseURL: env.BETTER_AUTH_URL,
10995
+ ],
10996
+ emailAndPassword: {
10997
+ enabled: true,
10998
+ },
10999
+ secret: env.BETTER_AUTH_SECRET,
11000
+ baseURL: env.BETTER_AUTH_URL,
10905
11001
  {{#if (ne backend "self")}}
10906
- advanced: {
10907
- defaultCookieAttributes: {
10908
- sameSite: "none",
10909
- secure: true,
10910
- httpOnly: true,
11002
+ advanced: {
11003
+ defaultCookieAttributes: {
11004
+ sameSite: "none",
11005
+ secure: true,
11006
+ httpOnly: true,
11007
+ },
10911
11008
  },
10912
- },
10913
11009
  {{/if}}
10914
- plugins: [
11010
+ plugins: [
10915
11011
  {{#if (eq payments "polar")}}
10916
- polar({
10917
- client: polarClient,
10918
- createCustomerOnSignUp: true,
10919
- enableCustomerPortal: true,
10920
- use: [
10921
- checkout({
10922
- products: [
10923
- {
10924
- productId: "your-product-id",
10925
- slug: "pro",
10926
- },
10927
- ],
10928
- successUrl: env.POLAR_SUCCESS_URL,
10929
- authenticatedUsersOnly: true,
10930
- }),
10931
- portal(),
10932
- ],
10933
- }),
11012
+ polar({
11013
+ client: polarClient,
11014
+ createCustomerOnSignUp: true,
11015
+ enableCustomerPortal: true,
11016
+ use: [
11017
+ checkout({
11018
+ products: [
11019
+ {
11020
+ productId: "your-product-id",
11021
+ slug: "pro",
11022
+ },
11023
+ ],
11024
+ successUrl: env.POLAR_SUCCESS_URL,
11025
+ authenticatedUsersOnly: true,
11026
+ }),
11027
+ portal(),
11028
+ ],
11029
+ }),
11030
+ {{/if}}
11031
+ ],
11032
+ });
11033
+ }
11034
+
11035
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
11036
+ export const auth = createAuth();
10934
11037
  {{/if}}
10935
- ],
10936
- });
10937
11038
  {{/if}}
10938
11039
 
10939
11040
  {{#if (eq runtime "workers")}}
@@ -10944,79 +11045,83 @@ import { env } from "@{{projectName}}/env/server";
10944
11045
  import { polar, checkout, portal } from "@polar-sh/better-auth";
10945
11046
  import { polarClient } from "./lib/payments";
10946
11047
  {{/if}}
10947
- import { db } from "@{{projectName}}/db";
11048
+ import { createDb } from "@{{projectName}}/db";
10948
11049
  import * as schema from "@{{projectName}}/db/schema/auth";
10949
11050
 
10950
11051
 
10951
- export const auth = betterAuth({
10952
- database: drizzleAdapter(db, {
11052
+ export function createAuth() {
11053
+ const db = createDb();
11054
+
11055
+ return betterAuth({
11056
+ database: drizzleAdapter(db, {
10953
11057
  {{#if (eq database "postgres")}}provider: "pg",{{/if}}
10954
11058
  {{#if (eq database "sqlite")}}provider: "sqlite",{{/if}}
10955
11059
  {{#if (eq database "mysql")}}provider: "mysql",{{/if}}
10956
- schema: schema,
10957
- }),
10958
- trustedOrigins: [
10959
- env.CORS_ORIGIN,
11060
+ schema: schema,
11061
+ }),
11062
+ trustedOrigins: [
11063
+ env.CORS_ORIGIN,
10960
11064
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
10961
- "{{projectName}}://",
10962
- ...(env.NODE_ENV === "development"
10963
- ? [
10964
- "exp://",
10965
- "exp://**",
10966
- "exp://192.168.*.*:*/**",
10967
- "http://localhost:8081",
10968
- ]
10969
- : []),
11065
+ "{{projectName}}://",
11066
+ ...(env.NODE_ENV === "development"
11067
+ ? [
11068
+ "exp://",
11069
+ "exp://**",
11070
+ "exp://192.168.*.*:*/**",
11071
+ "http://localhost:8081",
11072
+ ]
11073
+ : []),
10970
11074
  {{/if}}
10971
- ],
10972
- emailAndPassword: {
10973
- enabled: true,
10974
- },
10975
- // uncomment cookieCache setting when ready to deploy to Cloudflare using *.workers.dev domains
10976
- // session: {
10977
- // cookieCache: {
10978
- // enabled: true,
10979
- // maxAge: 60,
10980
- // },
10981
- // },
10982
- secret: env.BETTER_AUTH_SECRET,
10983
- baseURL: env.BETTER_AUTH_URL,
10984
- advanced: {
10985
- defaultCookieAttributes: {
10986
- sameSite: "none",
10987
- secure: true,
10988
- httpOnly: true,
11075
+ ],
11076
+ emailAndPassword: {
11077
+ enabled: true,
10989
11078
  },
10990
- // uncomment crossSubDomainCookies setting when ready to deploy and replace <your-workers-subdomain> with your actual workers subdomain
10991
- // https://developers.cloudflare.com/workers/wrangler/configuration/#workersdev
10992
- // crossSubDomainCookies: {
10993
- // enabled: true,
10994
- // domain: "<your-workers-subdomain>",
11079
+ // uncomment cookieCache setting when ready to deploy to Cloudflare using *.workers.dev domains
11080
+ // session: {
11081
+ // cookieCache: {
11082
+ // enabled: true,
11083
+ // maxAge: 60,
11084
+ // },
10995
11085
  // },
10996
- },
11086
+ secret: env.BETTER_AUTH_SECRET,
11087
+ baseURL: env.BETTER_AUTH_URL,
11088
+ advanced: {
11089
+ defaultCookieAttributes: {
11090
+ sameSite: "none",
11091
+ secure: true,
11092
+ httpOnly: true,
11093
+ },
11094
+ // uncomment crossSubDomainCookies setting when ready to deploy and replace <your-workers-subdomain> with your actual workers subdomain
11095
+ // https://developers.cloudflare.com/workers/wrangler/configuration/#workersdev
11096
+ // crossSubDomainCookies: {
11097
+ // enabled: true,
11098
+ // domain: "<your-workers-subdomain>",
11099
+ // },
11100
+ },
10997
11101
  {{#if (eq payments "polar")}}
10998
- plugins: [
10999
- polar({
11000
- client: polarClient,
11001
- createCustomerOnSignUp: true,
11002
- enableCustomerPortal: true,
11003
- use: [
11004
- checkout({
11005
- products: [
11006
- {
11007
- productId: "your-product-id",
11008
- slug: "pro",
11009
- },
11010
- ],
11011
- successUrl: env.POLAR_SUCCESS_URL,
11012
- authenticatedUsersOnly: true,
11013
- }),
11014
- portal(),
11015
- ],
11016
- }),
11017
- ],
11102
+ plugins: [
11103
+ polar({
11104
+ client: polarClient,
11105
+ createCustomerOnSignUp: true,
11106
+ enableCustomerPortal: true,
11107
+ use: [
11108
+ checkout({
11109
+ products: [
11110
+ {
11111
+ productId: "your-product-id",
11112
+ slug: "pro",
11113
+ },
11114
+ ],
11115
+ successUrl: env.POLAR_SUCCESS_URL,
11116
+ authenticatedUsersOnly: true,
11117
+ }),
11118
+ portal(),
11119
+ ],
11120
+ }),
11121
+ ],
11018
11122
  {{/if}}
11019
- });
11123
+ });
11124
+ }
11020
11125
  {{/if}}
11021
11126
  {{/if}}
11022
11127
 
@@ -11030,59 +11135,65 @@ import { polarClient } from "./lib/payments";
11030
11135
  {{/if}}
11031
11136
  import { client } from "@{{projectName}}/db";
11032
11137
 
11033
- export const auth = betterAuth({
11034
- database: mongodbAdapter(client),
11035
- trustedOrigins: [
11036
- env.CORS_ORIGIN,
11138
+ export function createAuth() {
11139
+ return betterAuth({
11140
+ database: mongodbAdapter(client),
11141
+ trustedOrigins: [
11142
+ env.CORS_ORIGIN,
11037
11143
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
11038
- "{{projectName}}://",
11039
- ...(env.NODE_ENV === "development"
11040
- ? [
11041
- "exp://",
11042
- "exp://**",
11043
- "exp://192.168.*.*:*/**",
11044
- "http://localhost:8081",
11045
- ]
11046
- : []),
11144
+ "{{projectName}}://",
11145
+ ...(env.NODE_ENV === "development"
11146
+ ? [
11147
+ "exp://",
11148
+ "exp://**",
11149
+ "exp://192.168.*.*:*/**",
11150
+ "http://localhost:8081",
11151
+ ]
11152
+ : []),
11047
11153
  {{/if}}
11048
- ],
11049
- emailAndPassword: {
11050
- enabled: true,
11051
- },
11052
- secret: env.BETTER_AUTH_SECRET,
11053
- baseURL: env.BETTER_AUTH_URL,
11154
+ ],
11155
+ emailAndPassword: {
11156
+ enabled: true,
11157
+ },
11158
+ secret: env.BETTER_AUTH_SECRET,
11159
+ baseURL: env.BETTER_AUTH_URL,
11054
11160
  {{#if (ne backend "self")}}
11055
- advanced: {
11056
- defaultCookieAttributes: {
11057
- sameSite: "none",
11058
- secure: true,
11059
- httpOnly: true,
11161
+ advanced: {
11162
+ defaultCookieAttributes: {
11163
+ sameSite: "none",
11164
+ secure: true,
11165
+ httpOnly: true,
11166
+ },
11060
11167
  },
11061
- },
11062
11168
  {{/if}}
11063
11169
  {{#if (eq payments "polar")}}
11064
- plugins: [
11065
- polar({
11066
- client: polarClient,
11067
- createCustomerOnSignUp: true,
11068
- enableCustomerPortal: true,
11069
- use: [
11070
- checkout({
11071
- products: [
11072
- {
11073
- productId: "your-product-id",
11074
- slug: "pro",
11075
- },
11076
- ],
11077
- successUrl: env.POLAR_SUCCESS_URL,
11078
- authenticatedUsersOnly: true,
11079
- }),
11080
- portal(),
11081
- ],
11082
- }),
11083
- ],
11170
+ plugins: [
11171
+ polar({
11172
+ client: polarClient,
11173
+ createCustomerOnSignUp: true,
11174
+ enableCustomerPortal: true,
11175
+ use: [
11176
+ checkout({
11177
+ products: [
11178
+ {
11179
+ productId: "your-product-id",
11180
+ slug: "pro",
11181
+ },
11182
+ ],
11183
+ successUrl: env.POLAR_SUCCESS_URL,
11184
+ authenticatedUsersOnly: true,
11185
+ }),
11186
+ portal(),
11187
+ ],
11188
+ }),
11189
+ ],
11190
+ {{/if}}
11191
+ });
11192
+ }
11193
+
11194
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
11195
+ export const auth = createAuth();
11084
11196
  {{/if}}
11085
- });
11086
11197
  {{/if}}
11087
11198
 
11088
11199
  {{#if (eq orm "none")}}
@@ -11094,59 +11205,65 @@ import { polarClient } from "./lib/payments";
11094
11205
  {{/if}}
11095
11206
 
11096
11207
 
11097
- export const auth = betterAuth({
11098
- database: "", // Invalid configuration
11099
- trustedOrigins: [
11100
- env.CORS_ORIGIN,
11208
+ export function createAuth() {
11209
+ return betterAuth({
11210
+ database: "", // Invalid configuration
11211
+ trustedOrigins: [
11212
+ env.CORS_ORIGIN,
11101
11213
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
11102
- "{{projectName}}://",
11103
- ...(env.NODE_ENV === "development"
11104
- ? [
11105
- "exp://",
11106
- "exp://**",
11107
- "exp://192.168.*.*:*/**",
11108
- "http://localhost:8081",
11109
- ]
11110
- : []),
11214
+ "{{projectName}}://",
11215
+ ...(env.NODE_ENV === "development"
11216
+ ? [
11217
+ "exp://",
11218
+ "exp://**",
11219
+ "exp://192.168.*.*:*/**",
11220
+ "http://localhost:8081",
11221
+ ]
11222
+ : []),
11111
11223
  {{/if}}
11112
- ],
11113
- emailAndPassword: {
11114
- enabled: true,
11115
- },
11116
- secret: env.BETTER_AUTH_SECRET,
11117
- baseURL: env.BETTER_AUTH_URL,
11224
+ ],
11225
+ emailAndPassword: {
11226
+ enabled: true,
11227
+ },
11228
+ secret: env.BETTER_AUTH_SECRET,
11229
+ baseURL: env.BETTER_AUTH_URL,
11118
11230
  {{#if (ne backend "self")}}
11119
- advanced: {
11120
- defaultCookieAttributes: {
11121
- sameSite: "none",
11122
- secure: true,
11123
- httpOnly: true,
11231
+ advanced: {
11232
+ defaultCookieAttributes: {
11233
+ sameSite: "none",
11234
+ secure: true,
11235
+ httpOnly: true,
11236
+ },
11124
11237
  },
11125
- },
11126
11238
  {{/if}}
11127
11239
  {{#if (eq payments "polar")}}
11128
- plugins: [
11129
- polar({
11130
- client: polarClient,
11131
- createCustomerOnSignUp: true,
11132
- enableCustomerPortal: true,
11133
- use: [
11134
- checkout({
11135
- products: [
11136
- {
11137
- productId: "your-product-id",
11138
- slug: "pro",
11139
- },
11140
- ],
11141
- successUrl: env.POLAR_SUCCESS_URL,
11142
- authenticatedUsersOnly: true,
11143
- }),
11144
- portal(),
11145
- ],
11146
- }),
11147
- ],
11240
+ plugins: [
11241
+ polar({
11242
+ client: polarClient,
11243
+ createCustomerOnSignUp: true,
11244
+ enableCustomerPortal: true,
11245
+ use: [
11246
+ checkout({
11247
+ products: [
11248
+ {
11249
+ productId: "your-product-id",
11250
+ slug: "pro",
11251
+ },
11252
+ ],
11253
+ successUrl: env.POLAR_SUCCESS_URL,
11254
+ authenticatedUsersOnly: true,
11255
+ }),
11256
+ portal(),
11257
+ ],
11258
+ }),
11259
+ ],
11260
+ {{/if}}
11261
+ });
11262
+ }
11263
+
11264
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
11265
+ export const auth = createAuth();
11148
11266
  {{/if}}
11149
- });
11150
11267
  {{/if}}
11151
11268
  `],
11152
11269
  ["auth/better-auth/server/base/tsconfig.json.hbs", `{
@@ -12623,13 +12740,19 @@ export default function Dashboard({
12623
12740
  import Dashboard from "./dashboard";
12624
12741
  import { headers } from "next/headers";
12625
12742
  {{#if (eq backend "self")}}
12743
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
12744
+ import { createAuth } from "@{{projectName}}/auth";
12745
+ {{else}}
12626
12746
  import { auth } from "@{{projectName}}/auth";
12627
12747
  {{/if}}
12748
+ {{/if}}
12749
+ {{#if (or (ne backend "self") (eq payments "polar"))}}
12628
12750
  import { authClient } from "@/lib/auth-client";
12751
+ {{/if}}
12629
12752
 
12630
12753
  export default async function DashboardPage() {
12631
12754
  {{#if (eq backend "self")}}
12632
- const session = await auth.api.getSession({
12755
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
12633
12756
  headers: await headers(),
12634
12757
  });
12635
12758
  {{else}}
@@ -14313,12 +14436,16 @@ export const getUser = createServerFn({ method: "GET" }).middleware([authMiddlew
14313
14436
  return context.session
14314
14437
  })`],
14315
14438
  ["auth/better-auth/web/react/tanstack-start/src/middleware/auth.ts.hbs", `{{#if (eq backend "self")}}
14439
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
14440
+ import { createAuth } from "@{{projectName}}/auth";
14441
+ {{else}}
14316
14442
  import { auth } from "@{{projectName}}/auth";
14443
+ {{/if}}
14317
14444
  import { createMiddleware } from "@tanstack/react-start";
14318
14445
 
14319
14446
 
14320
14447
  export const authMiddleware = createMiddleware().server(async ({ next, request }) => {
14321
- const session = await auth.api.getSession({
14448
+ const session = await {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}createAuth(){{else}}auth{{/if}}.api.getSession({
14322
14449
  headers: request.headers,
14323
14450
  })
14324
14451
  return next({
@@ -17521,8 +17648,12 @@ import { createContext } from "@{{projectName}}/api/context";
17521
17648
  import { appRouter } from "@{{projectName}}/api/routers/index";
17522
17649
  {{/if}}
17523
17650
  {{#if (eq auth "better-auth")}}
17651
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
17652
+ import { createAuth } from "@{{projectName}}/auth";
17653
+ {{else}}
17524
17654
  import { auth } from "@{{projectName}}/auth";
17525
17655
  {{/if}}
17656
+ {{/if}}
17526
17657
  import { Hono } from "hono";
17527
17658
  import { cors } from "hono/cors";
17528
17659
  import { logger } from "hono/logger";
@@ -17555,7 +17686,16 @@ app.use(
17555
17686
  );
17556
17687
 
17557
17688
  {{#if (eq auth "better-auth")}}
17558
- app.on(["POST", "GET"], "/api/auth/*", (c) => auth.handler(c.req.raw));
17689
+ app.on(
17690
+ ["POST", "GET"],
17691
+ "/api/auth/*",
17692
+ (c) =>
17693
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
17694
+ createAuth().handler(c.req.raw)
17695
+ {{else}}
17696
+ auth.handler(c.req.raw)
17697
+ {{/if}}
17698
+ );
17559
17699
  {{/if}}
17560
17700
 
17561
17701
  {{#if (eq api "orpc")}}
@@ -17910,23 +18050,31 @@ import * as schema from "./schema";
17910
18050
  {{#if (eq dbSetup "planetscale")}}
17911
18051
  import { drizzle } from "drizzle-orm/planetscale-serverless";
17912
18052
 
17913
- export const db = drizzle({
17914
- connection: {
17915
- host: env.DATABASE_HOST,
17916
- username: env.DATABASE_USERNAME,
17917
- password: env.DATABASE_PASSWORD,
17918
- },
17919
- schema,
17920
- });
18053
+ export function createDb() {
18054
+ return drizzle({
18055
+ connection: {
18056
+ host: env.DATABASE_HOST,
18057
+ username: env.DATABASE_USERNAME,
18058
+ password: env.DATABASE_PASSWORD,
18059
+ },
18060
+ schema,
18061
+ });
18062
+ }
17921
18063
  {{else}}
17922
18064
  import { drizzle } from "drizzle-orm/mysql2";
17923
18065
 
17924
- export const db = drizzle({
17925
- connection: {
17926
- uri: env.DATABASE_URL,
17927
- },
17928
- schema,
17929
- });
18066
+ export function createDb() {
18067
+ return drizzle({
18068
+ connection: {
18069
+ uri: env.DATABASE_URL,
18070
+ },
18071
+ schema,
18072
+ });
18073
+ }
18074
+ {{/if}}
18075
+
18076
+ {{#if (and (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18077
+ export const db = createDb();
17930
18078
  {{/if}}
17931
18079
  {{/if}}
17932
18080
 
@@ -17937,24 +18085,28 @@ import * as schema from "./schema";
17937
18085
  import { drizzle } from "drizzle-orm/planetscale-serverless";
17938
18086
  import { env } from "@{{projectName}}/env/server";
17939
18087
 
17940
- export const db = drizzle({
17941
- connection: {
17942
- host: env.DATABASE_HOST,
17943
- username: env.DATABASE_USERNAME,
17944
- password: env.DATABASE_PASSWORD,
17945
- },
17946
- schema,
17947
- });
18088
+ export function createDb() {
18089
+ return drizzle({
18090
+ connection: {
18091
+ host: env.DATABASE_HOST,
18092
+ username: env.DATABASE_USERNAME,
18093
+ password: env.DATABASE_PASSWORD,
18094
+ },
18095
+ schema,
18096
+ });
18097
+ }
17948
18098
  {{else}}
17949
18099
  import { drizzle } from "drizzle-orm/mysql2";
17950
18100
  import { env } from "@{{projectName}}/env/server";
17951
18101
 
17952
- export const db = drizzle({
17953
- connection: {
17954
- uri: env.DATABASE_URL,
17955
- },
17956
- schema,
17957
- });
18102
+ export function createDb() {
18103
+ return drizzle({
18104
+ connection: {
18105
+ uri: env.DATABASE_URL,
18106
+ },
18107
+ schema,
18108
+ });
18109
+ }
17958
18110
  {{/if}}
17959
18111
  {{/if}}
17960
18112
  `],
@@ -17986,12 +18138,32 @@ import * as schema from "./schema";
17986
18138
  import { neon } from '@neondatabase/serverless';
17987
18139
  import { drizzle } from 'drizzle-orm/neon-http';
17988
18140
 
17989
- const sql = neon(env.DATABASE_URL);
17990
- export const db = drizzle(sql, { schema });
18141
+ export function createDb() {
18142
+ const sql = neon(env.DATABASE_URL);
18143
+ return drizzle(sql, { schema });
18144
+ }
17991
18145
  {{else}}
17992
18146
  import { drizzle } from "drizzle-orm/node-postgres";
18147
+ {{#if (and (eq backend "self") (eq webDeploy "cloudflare"))}}
18148
+ import { Pool } from "pg";
18149
+ {{/if}}
18150
+
18151
+ export function createDb() {
18152
+ {{#if (and (eq backend "self") (eq webDeploy "cloudflare"))}}
18153
+ const pool = new Pool({
18154
+ connectionString: env.DATABASE_URL,
18155
+ maxUses: 1,
18156
+ });
17993
18157
 
17994
- export const db = drizzle(env.DATABASE_URL, { schema });
18158
+ return drizzle({ client: pool, schema });
18159
+ {{else}}
18160
+ return drizzle(env.DATABASE_URL, { schema });
18161
+ {{/if}}
18162
+ }
18163
+ {{/if}}
18164
+
18165
+ {{#if (and (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18166
+ export const db = createDb();
17995
18167
  {{/if}}
17996
18168
  {{/if}}
17997
18169
 
@@ -18003,15 +18175,26 @@ import { neon } from '@neondatabase/serverless';
18003
18175
  import { drizzle } from 'drizzle-orm/neon-http';
18004
18176
  import { env } from "@{{projectName}}/env/server";
18005
18177
 
18006
- const sql = neon(env.DATABASE_URL || "");
18007
- export const db = drizzle(sql, { schema });
18178
+ export function createDb() {
18179
+ const sql = neon(env.DATABASE_URL || "");
18180
+ return drizzle(sql, { schema });
18181
+ }
18008
18182
  {{else}}
18009
18183
  import { drizzle } from "drizzle-orm/node-postgres";
18010
18184
  import { env } from "@{{projectName}}/env/server";
18185
+ import { Pool } from "pg";
18011
18186
 
18012
- export const db = drizzle(env.DATABASE_URL || "", { schema });
18187
+ export function createDb() {
18188
+ const pool = new Pool({
18189
+ connectionString: env.DATABASE_URL || "",
18190
+ maxUses: 1,
18191
+ });
18192
+
18193
+ return drizzle({ client: pool, schema });
18194
+ }
18013
18195
  {{/if}}
18014
- {{/if}}`],
18196
+ {{/if}}
18197
+ `],
18015
18198
  ["db/drizzle/sqlite/drizzle.config.ts.hbs", `import { defineConfig } from "drizzle-kit";
18016
18199
  import dotenv from "dotenv";
18017
18200
 
@@ -18041,44 +18224,50 @@ export default defineConfig({
18041
18224
  {{/if}}
18042
18225
  });
18043
18226
  `],
18044
- ["db/drizzle/sqlite/src/index.ts.hbs", `{{#if (or (eq runtime "bun") (eq runtime "node") (eq runtime "none"))}}
18227
+ ["db/drizzle/sqlite/src/index.ts.hbs", `{{#if (eq dbSetup "d1")}}
18228
+ import * as schema from "./schema";
18229
+ import { drizzle } from "drizzle-orm/d1";
18230
+ import { env } from "@{{projectName}}/env/server";
18231
+
18232
+ export function createDb() {
18233
+ return drizzle(env.DB, { schema });
18234
+ }
18235
+ {{else if (or (eq runtime "bun") (eq runtime "node") (eq runtime "none"))}}
18045
18236
  import { env } from "@{{projectName}}/env/server";
18046
18237
  import * as schema from "./schema";
18047
18238
  import { drizzle } from "drizzle-orm/libsql";
18048
18239
  import { createClient } from "@libsql/client";
18049
18240
 
18050
- const client = createClient({
18051
- url: env.DATABASE_URL,
18241
+ export function createDb() {
18242
+ const client = createClient({
18243
+ url: env.DATABASE_URL,
18052
18244
  {{#if (eq dbSetup "turso")}}
18053
- authToken: env.DATABASE_AUTH_TOKEN,
18245
+ authToken: env.DATABASE_AUTH_TOKEN,
18054
18246
  {{/if}}
18055
- });
18247
+ });
18056
18248
 
18057
- export const db = drizzle({ client, schema });
18058
- {{/if}}
18249
+ return drizzle({ client, schema });
18250
+ }
18059
18251
 
18060
- {{#if (eq runtime "workers")}}
18252
+ {{#if (and (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18253
+ export const db = createDb();
18254
+ {{/if}}
18255
+ {{else if (eq runtime "workers")}}
18061
18256
  import * as schema from "./schema";
18062
-
18063
- {{#if (eq dbSetup "d1")}}
18064
- import { drizzle } from "drizzle-orm/d1";
18065
- import { env } from "@{{projectName}}/env/server";
18066
-
18067
- export const db = drizzle(env.DB, { schema });
18068
- {{else}}
18069
18257
  import { drizzle } from "drizzle-orm/libsql";
18070
18258
  import { env } from "@{{projectName}}/env/server";
18071
18259
  import { createClient } from "@libsql/client";
18072
18260
 
18073
- const client = createClient({
18074
- url: env.DATABASE_URL || "",
18261
+ export function createDb() {
18262
+ const client = createClient({
18263
+ url: env.DATABASE_URL || "",
18075
18264
  {{#if (eq dbSetup "turso")}}
18076
- authToken: env.DATABASE_AUTH_TOKEN,
18265
+ authToken: env.DATABASE_AUTH_TOKEN,
18077
18266
  {{/if}}
18078
- });
18267
+ });
18079
18268
 
18080
- export const db = drizzle({ client, schema });
18081
- {{/if}}
18269
+ return drizzle({ client, schema });
18270
+ }
18082
18271
  {{/if}}
18083
18272
  `],
18084
18273
  ["db/mongoose/mongodb/src/index.ts.hbs", `import mongoose from "mongoose";
@@ -18186,26 +18375,28 @@ import { env } from "@{{projectName}}/env/server";
18186
18375
  {{#if (eq dbSetup "planetscale")}}
18187
18376
  import { PrismaPlanetScale } from "@prisma/adapter-planetscale";
18188
18377
 
18189
- const adapter = new PrismaPlanetScale({ url: env.DATABASE_URL });
18190
- const prisma = new PrismaClient({ adapter });
18378
+ export function createPrismaClient() {
18379
+ const adapter = new PrismaPlanetScale({ url: env.DATABASE_URL });
18380
+ return new PrismaClient({ adapter });
18381
+ }
18191
18382
  {{else}}
18192
18383
  import { PrismaMariaDb } from "@prisma/adapter-mariadb";
18193
18384
 
18194
- const databaseUrl: string = env.DATABASE_URL;
18195
- const url: URL = new URL(databaseUrl);
18196
- const connectionConfig = {
18197
- host: url.hostname,
18198
- port: parseInt(url.port || "3306"),
18199
- user: url.username,
18200
- password: url.password,
18201
- database: url.pathname.slice(1),
18202
- };
18385
+ export function createPrismaClient() {
18386
+ const databaseUrl: string = env.DATABASE_URL;
18387
+ const url: URL = new URL(databaseUrl);
18388
+ const connectionConfig = {
18389
+ host: url.hostname,
18390
+ port: parseInt(url.port || "3306"),
18391
+ user: url.username,
18392
+ password: url.password,
18393
+ database: url.pathname.slice(1),
18394
+ };
18203
18395
 
18204
- const adapter = new PrismaMariaDb(connectionConfig);
18205
- const prisma = new PrismaClient({ adapter });
18396
+ const adapter = new PrismaMariaDb(connectionConfig);
18397
+ return new PrismaClient({ adapter });
18398
+ }
18206
18399
  {{/if}}
18207
-
18208
- export default prisma;
18209
18400
  {{else}}
18210
18401
  import { PrismaClient } from "../prisma/generated/client";
18211
18402
  import { env } from "@{{projectName}}/env/server";
@@ -18213,27 +18404,35 @@ import { env } from "@{{projectName}}/env/server";
18213
18404
  {{#if (eq dbSetup "planetscale")}}
18214
18405
  import { PrismaPlanetScale } from "@prisma/adapter-planetscale";
18215
18406
 
18216
- const adapter = new PrismaPlanetScale({ url: env.DATABASE_URL });
18217
- const prisma = new PrismaClient({ adapter });
18407
+ export function createPrismaClient() {
18408
+ const adapter = new PrismaPlanetScale({ url: env.DATABASE_URL });
18409
+ return new PrismaClient({ adapter });
18410
+ }
18218
18411
  {{else}}
18219
18412
  import { PrismaMariaDb } from "@prisma/adapter-mariadb";
18220
18413
 
18221
- const databaseUrl: string = env.DATABASE_URL;
18222
- const url: URL = new URL(databaseUrl);
18223
- const connectionConfig = {
18224
- host: url.hostname,
18225
- port: parseInt(url.port || "3306"),
18226
- user: url.username,
18227
- password: url.password,
18228
- database: url.pathname.slice(1),
18229
- };
18414
+ export function createPrismaClient() {
18415
+ const databaseUrl: string = env.DATABASE_URL;
18416
+ const url: URL = new URL(databaseUrl);
18417
+ const connectionConfig = {
18418
+ host: url.hostname,
18419
+ port: parseInt(url.port || "3306"),
18420
+ user: url.username,
18421
+ password: url.password,
18422
+ database: url.pathname.slice(1),
18423
+ };
18230
18424
 
18231
- const adapter = new PrismaMariaDb(connectionConfig);
18232
- const prisma = new PrismaClient({ adapter });
18425
+ const adapter = new PrismaMariaDb(connectionConfig);
18426
+ return new PrismaClient({ adapter });
18427
+ }
18233
18428
  {{/if}}
18234
18429
 
18430
+ {{#if (and (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18431
+ const prisma = createPrismaClient();
18235
18432
  export default prisma;
18236
- {{/if}}`],
18433
+ {{/if}}
18434
+ {{/if}}
18435
+ `],
18237
18436
  ["db/prisma/postgres/prisma.config.ts.hbs", `import path from "node:path";
18238
18437
  import { defineConfig, env } from 'prisma/config'
18239
18438
  import dotenv from 'dotenv'
@@ -18287,61 +18486,86 @@ import { neonConfig } from "@neondatabase/serverless";
18287
18486
 
18288
18487
  neonConfig.poolQueryViaFetch = true;
18289
18488
 
18290
- const prisma = new PrismaClient({
18291
- adapter: new PrismaNeon({
18292
- connectionString: env.DATABASE_URL,
18293
- }),
18294
- });
18489
+ export function createPrismaClient() {
18490
+ return new PrismaClient({
18491
+ adapter: new PrismaNeon({
18492
+ connectionString: env.DATABASE_URL,
18493
+ }),
18494
+ });
18495
+ }
18295
18496
 
18296
18497
  {{else if (eq dbSetup "prisma-postgres")}}
18297
18498
  import { PrismaPg } from "@prisma/adapter-pg";
18298
18499
 
18299
- const adapter = new PrismaPg({
18300
- connectionString: env.DATABASE_URL,
18301
- });
18500
+ export function createPrismaClient() {
18501
+ const adapter = new PrismaPg({
18502
+ connectionString: env.DATABASE_URL,
18503
+ maxUses: 1,
18504
+ });
18302
18505
 
18303
- const prisma = new PrismaClient({ adapter });
18506
+ return new PrismaClient({ adapter });
18507
+ }
18304
18508
 
18305
18509
  {{else}}
18306
18510
  import { PrismaPg } from "@prisma/adapter-pg";
18307
18511
 
18308
- const adapter = new PrismaPg({ connectionString: env.DATABASE_URL });
18309
- const prisma = new PrismaClient({ adapter });
18512
+ export function createPrismaClient() {
18513
+ const adapter = new PrismaPg({
18514
+ connectionString: env.DATABASE_URL,
18515
+ maxUses: 1,
18516
+ });
18517
+ return new PrismaClient({ adapter });
18518
+ }
18310
18519
 
18311
18520
  {{/if}}
18312
-
18313
- export default prisma;
18314
18521
  {{else}}
18315
18522
  import { PrismaClient } from "../prisma/generated/client";
18316
18523
  import { env } from "@{{projectName}}/env/server";
18317
18524
  {{#if (eq dbSetup "neon")}}
18318
18525
  import { PrismaNeon } from "@prisma/adapter-neon";
18319
18526
 
18320
- const adapter = new PrismaNeon({
18321
- connectionString: env.DATABASE_URL,
18322
- });
18527
+ export function createPrismaClient() {
18528
+ const adapter = new PrismaNeon({
18529
+ connectionString: env.DATABASE_URL,
18530
+ });
18323
18531
 
18324
- const prisma = new PrismaClient({ adapter });
18532
+ return new PrismaClient({ adapter });
18533
+ }
18325
18534
 
18326
18535
  {{else if (eq dbSetup "prisma-postgres")}}
18327
18536
  import { PrismaPg } from "@prisma/adapter-pg";
18328
18537
 
18329
- const adapter = new PrismaPg({
18330
- connectionString: env.DATABASE_URL,
18331
- });
18538
+ export function createPrismaClient() {
18539
+ const adapter = new PrismaPg({
18540
+ connectionString: env.DATABASE_URL,
18541
+ {{#if (and (eq backend "self") (eq webDeploy "cloudflare"))}}
18542
+ maxUses: 1,
18543
+ {{/if}}
18544
+ });
18332
18545
 
18333
- const prisma = new PrismaClient({ adapter });
18546
+ return new PrismaClient({ adapter });
18547
+ }
18334
18548
 
18335
18549
  {{else}}
18336
18550
  import { PrismaPg } from "@prisma/adapter-pg";
18337
18551
 
18338
- const adapter = new PrismaPg({ connectionString: env.DATABASE_URL });
18339
- const prisma = new PrismaClient({ adapter });
18340
-
18552
+ export function createPrismaClient() {
18553
+ const adapter = new PrismaPg({
18554
+ connectionString: env.DATABASE_URL,
18555
+ {{#if (and (eq backend "self") (eq webDeploy "cloudflare"))}}
18556
+ maxUses: 1,
18341
18557
  {{/if}}
18558
+ });
18559
+ return new PrismaClient({ adapter });
18560
+ }
18342
18561
 
18562
+ {{/if}}
18563
+ {{#if (and (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18564
+ const prisma = createPrismaClient();
18343
18565
  export default prisma;
18344
- {{/if}}`],
18566
+ {{/if}}
18567
+ {{/if}}
18568
+ `],
18345
18569
  ["db/prisma/sqlite/prisma.config.ts.hbs", `import path from "node:path";
18346
18570
  import { defineConfig, env } from "prisma/config";
18347
18571
  import dotenv from "dotenv";
@@ -18392,25 +18616,36 @@ datasource db {
18392
18616
  import { PrismaD1 } from "@prisma/adapter-d1";
18393
18617
  import { env } from "@{{projectName}}/env/server";
18394
18618
 
18395
- const adapter = new PrismaD1(env.DB);
18396
- const prisma = new PrismaClient({ adapter });
18619
+ export function createPrismaClient() {
18620
+ const adapter = new PrismaD1(env.DB);
18621
+ return new PrismaClient({ adapter });
18622
+ }
18397
18623
 
18624
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18625
+ const prisma = createPrismaClient();
18398
18626
  export default prisma;
18627
+ {{/if}}
18399
18628
  {{else}}
18400
18629
  import { PrismaLibSql } from "@prisma/adapter-libsql";
18401
18630
  import { env } from "@{{projectName}}/env/server";
18402
18631
 
18403
- const adapter = new PrismaLibSql({
18404
- url: env.DATABASE_URL,
18632
+ export function createPrismaClient() {
18633
+ const adapter = new PrismaLibSql({
18634
+ url: env.DATABASE_URL,
18405
18635
  {{#if (eq dbSetup "turso")}}
18406
- authToken: env.DATABASE_AUTH_TOKEN || "",
18636
+ authToken: env.DATABASE_AUTH_TOKEN || "",
18407
18637
  {{/if}}
18408
- });
18638
+ });
18409
18639
 
18410
- const prisma = new PrismaClient({ adapter });
18640
+ return new PrismaClient({ adapter });
18641
+ }
18411
18642
 
18643
+ {{#if (and (ne runtime "workers") (ne serverDeploy "cloudflare") (or (ne backend "self") (ne webDeploy "cloudflare")))}}
18644
+ const prisma = createPrismaClient();
18412
18645
  export default prisma;
18413
- {{/if}}`],
18646
+ {{/if}}
18647
+ {{/if}}
18648
+ `],
18414
18649
  ["examples/ai/convex/packages/backend/convex/agent.ts.hbs", `import { Agent } from "@convex-dev/agent";
18415
18650
  import { google } from "@ai-sdk/google";
18416
18651
  import { components } from "./_generated/api";
@@ -22596,18 +22831,28 @@ export default function TodosScreen() {
22596
22831
  ["examples/todo/server/drizzle/base/src/routers/todo.ts.hbs", `{{#if (eq api "orpc")}}
22597
22832
  import { eq } from "drizzle-orm";
22598
22833
  import z from "zod";
22834
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22835
+ import { createDb } from "@{{projectName}}/db";
22836
+ {{else}}
22599
22837
  import { db } from "@{{projectName}}/db";
22838
+ {{/if}}
22600
22839
  import { todo } from "@{{projectName}}/db/schema/todo";
22601
22840
  import { publicProcedure } from "../index";
22602
22841
 
22603
22842
  export const todoRouter = {
22604
22843
  getAll: publicProcedure.handler(async () => {
22844
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22845
+ const db = createDb();
22846
+ {{/if}}
22605
22847
  return await db.select().from(todo);
22606
22848
  }),
22607
22849
 
22608
22850
  create: publicProcedure
22609
22851
  .input(z.object({ text: z.string().min(1) }))
22610
22852
  .handler(async ({ input }) => {
22853
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22854
+ const db = createDb();
22855
+ {{/if}}
22611
22856
  return await db
22612
22857
  .insert(todo)
22613
22858
  .values({
@@ -22618,6 +22863,9 @@ export const todoRouter = {
22618
22863
  toggle: publicProcedure
22619
22864
  .input(z.object({ id: z.number(), completed: z.boolean() }))
22620
22865
  .handler(async ({ input }) => {
22866
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22867
+ const db = createDb();
22868
+ {{/if}}
22621
22869
  return await db
22622
22870
  .update(todo)
22623
22871
  .set({ completed: input.completed })
@@ -22627,6 +22875,9 @@ export const todoRouter = {
22627
22875
  delete: publicProcedure
22628
22876
  .input(z.object({ id: z.number() }))
22629
22877
  .handler(async ({ input }) => {
22878
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22879
+ const db = createDb();
22880
+ {{/if}}
22630
22881
  return await db.delete(todo).where(eq(todo.id, input.id));
22631
22882
  }),
22632
22883
  };
@@ -22637,16 +22888,26 @@ import z from "zod";
22637
22888
  import { router, publicProcedure } from "../index";
22638
22889
  import { todo } from "@{{projectName}}/db/schema/todo";
22639
22890
  import { eq } from "drizzle-orm";
22891
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22892
+ import { createDb } from "@{{projectName}}/db";
22893
+ {{else}}
22640
22894
  import { db } from "@{{projectName}}/db";
22895
+ {{/if}}
22641
22896
 
22642
22897
  export const todoRouter = router({
22643
22898
  getAll: publicProcedure.query(async () => {
22899
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22900
+ const db = createDb();
22901
+ {{/if}}
22644
22902
  return await db.select().from(todo);
22645
22903
  }),
22646
22904
 
22647
22905
  create: publicProcedure
22648
22906
  .input(z.object({ text: z.string().min(1) }))
22649
22907
  .mutation(async ({ input }) => {
22908
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22909
+ const db = createDb();
22910
+ {{/if}}
22650
22911
  return await db.insert(todo).values({
22651
22912
  text: input.text,
22652
22913
  });
@@ -22655,6 +22916,9 @@ export const todoRouter = router({
22655
22916
  toggle: publicProcedure
22656
22917
  .input(z.object({ id: z.number(), completed: z.boolean() }))
22657
22918
  .mutation(async ({ input }) => {
22919
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22920
+ const db = createDb();
22921
+ {{/if}}
22658
22922
  return await db
22659
22923
  .update(todo)
22660
22924
  .set({ completed: input.completed })
@@ -22664,6 +22928,9 @@ export const todoRouter = router({
22664
22928
  delete: publicProcedure
22665
22929
  .input(z.object({ id: z.number() }))
22666
22930
  .mutation(async ({ input }) => {
22931
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
22932
+ const db = createDb();
22933
+ {{/if}}
22667
22934
  return await db.delete(todo).where(eq(todo.id, input.id));
22668
22935
  }),
22669
22936
  });
@@ -22787,11 +23054,18 @@ export { Todo };
22787
23054
  `],
22788
23055
  ["examples/todo/server/prisma/base/src/routers/todo.ts.hbs", `{{#if (eq api "orpc")}}
22789
23056
  import z from "zod";
23057
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23058
+ import { createPrismaClient } from "@{{projectName}}/db";
23059
+ {{else}}
22790
23060
  import prisma from "@{{projectName}}/db";
23061
+ {{/if}}
22791
23062
  import { publicProcedure } from "../index";
22792
23063
 
22793
23064
  export const todoRouter = {
22794
23065
  getAll: publicProcedure.handler(async () => {
23066
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23067
+ const prisma = createPrismaClient();
23068
+ {{/if}}
22795
23069
  return await prisma.todo.findMany({
22796
23070
  orderBy: {
22797
23071
  id: "asc",
@@ -22802,6 +23076,9 @@ export const todoRouter = {
22802
23076
  create: publicProcedure
22803
23077
  .input(z.object({ text: z.string().min(1) }))
22804
23078
  .handler(async ({ input }) => {
23079
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23080
+ const prisma = createPrismaClient();
23081
+ {{/if}}
22805
23082
  return await prisma.todo.create({
22806
23083
  data: {
22807
23084
  text: input.text,
@@ -22816,6 +23093,9 @@ export const todoRouter = {
22816
23093
  .input(z.object({ id: z.number(), completed: z.boolean() }))
22817
23094
  {{/if}}
22818
23095
  .handler(async ({ input }) => {
23096
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23097
+ const prisma = createPrismaClient();
23098
+ {{/if}}
22819
23099
  return await prisma.todo.update({
22820
23100
  where: { id: input.id },
22821
23101
  data: { completed: input.completed },
@@ -22829,6 +23109,9 @@ export const todoRouter = {
22829
23109
  .input(z.object({ id: z.number() }))
22830
23110
  {{/if}}
22831
23111
  .handler(async ({ input }) => {
23112
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23113
+ const prisma = createPrismaClient();
23114
+ {{/if}}
22832
23115
  return await prisma.todo.delete({
22833
23116
  where: { id: input.id },
22834
23117
  });
@@ -22839,11 +23122,18 @@ export const todoRouter = {
22839
23122
  {{#if (eq api "trpc")}}
22840
23123
  import { TRPCError } from "@trpc/server";
22841
23124
  import z from "zod";
23125
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23126
+ import { createPrismaClient } from "@{{projectName}}/db";
23127
+ {{else}}
22842
23128
  import prisma from "@{{projectName}}/db";
23129
+ {{/if}}
22843
23130
  import { publicProcedure, router } from "../index";
22844
23131
 
22845
23132
  export const todoRouter = router({
22846
23133
  getAll: publicProcedure.query(async () => {
23134
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23135
+ const prisma = createPrismaClient();
23136
+ {{/if}}
22847
23137
  return await prisma.todo.findMany({
22848
23138
  orderBy: {
22849
23139
  id: "asc"
@@ -22854,6 +23144,9 @@ export const todoRouter = router({
22854
23144
  create: publicProcedure
22855
23145
  .input(z.object({ text: z.string().min(1) }))
22856
23146
  .mutation(async ({ input }) => {
23147
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23148
+ const prisma = createPrismaClient();
23149
+ {{/if}}
22857
23150
  return await prisma.todo.create({
22858
23151
  data: {
22859
23152
  text: input.text,
@@ -22868,6 +23161,9 @@ export const todoRouter = router({
22868
23161
  .input(z.object({ id: z.number(), completed: z.boolean() }))
22869
23162
  {{/if}}
22870
23163
  .mutation(async ({ input }) => {
23164
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23165
+ const prisma = createPrismaClient();
23166
+ {{/if}}
22871
23167
  try {
22872
23168
  return await prisma.todo.update({
22873
23169
  where: { id: input.id },
@@ -22888,6 +23184,9 @@ export const todoRouter = router({
22888
23184
  .input(z.object({ id: z.number() }))
22889
23185
  {{/if}}
22890
23186
  .mutation(async ({ input }) => {
23187
+ {{#if (or (eq runtime "workers") (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
23188
+ const prisma = createPrismaClient();
23189
+ {{/if}}
22891
23190
  try {
22892
23191
  return await prisma.todo.delete({
22893
23192
  where: { id: input.id },
@@ -29154,28 +29453,28 @@ export function ThemeProvider({
29154
29453
  },
29155
29454
  "dependencies": {
29156
29455
  "@{{projectName}}/ui": "{{#if (eq packageManager "npm")}}*{{else}}workspace:*{{/if}}",
29157
- "@react-router/fs-routes": "^7.10.1",
29158
- "@react-router/node": "^7.10.1",
29159
- "@react-router/serve": "^7.10.1",
29160
- "isbot": "^5.1.28",
29161
- "lucide-react": "^0.546.0",
29456
+ "@react-router/fs-routes": "^7.14.1",
29457
+ "@react-router/node": "^7.14.1",
29458
+ "@react-router/serve": "^7.14.1",
29459
+ "isbot": "^5.1.39",
29460
+ "lucide-react": "^1.8.0",
29162
29461
  "next-themes": "^0.4.6",
29163
- "react": "^19.2.3",
29164
- "react-dom": "^19.2.3",
29165
- "react-router": "^7.10.1",
29166
- "sonner": "^2.0.5"
29462
+ "react": "^19.2.5",
29463
+ "react-dom": "^19.2.5",
29464
+ "react-router": "^7.14.1",
29465
+ "sonner": "^2.0.7"
29167
29466
  },
29168
29467
  "devDependencies": {
29169
- "@react-router/dev": "^7.10.1",
29170
- "@tailwindcss/vite": "^4.1.18",
29468
+ "@react-router/dev": "^7.14.1",
29469
+ "@tailwindcss/vite": "^4.2.2",
29171
29470
  "@types/node": "^20",
29172
- "@types/react": "^19.2.10",
29471
+ "@types/react": "^19.2.14",
29173
29472
  "@types/react-dom": "^19.2.3",
29174
29473
  "react-router-devtools": "^1.1.0",
29175
- "tailwindcss": "^4.1.18",
29474
+ "tailwindcss": "^4.2.2",
29176
29475
  "typescript": "^5.8.3",
29177
- "vite": "^7.2.7",
29178
- "vite-tsconfig-paths": "^5.1.4"
29476
+ "vite": "^8.0.8",
29477
+ "vite-tsconfig-paths": "^6.1.1"
29179
29478
  }
29180
29479
  }
29181
29480
  `],
@@ -29699,26 +29998,26 @@ export default defineConfig({
29699
29998
  "check-types": "vite build && tsc --noEmit"
29700
29999
  },
29701
30000
  "dependencies": {
29702
- "@hookform/resolvers": "^5.1.1",
30001
+ "@hookform/resolvers": "^5.2.2",
29703
30002
  "@{{projectName}}/ui": "{{#if (eq packageManager "npm")}}*{{else}}workspace:*{{/if}}",
29704
- "@tailwindcss/vite": "^4.1.18",
29705
- "@tanstack/react-router": "^1.141.1",
29706
- "lucide-react": "^0.546.0",
30003
+ "@tailwindcss/vite": "^4.2.2",
30004
+ "@tanstack/react-router": "^1.168.22",
30005
+ "lucide-react": "^1.8.0",
29707
30006
  "next-themes": "^0.4.6",
29708
- "react": "^19.2.3",
29709
- "react-dom": "^19.2.3",
29710
- "sonner": "^2.0.5"
30007
+ "react": "^19.2.5",
30008
+ "react-dom": "^19.2.5",
30009
+ "sonner": "^2.0.7"
29711
30010
  },
29712
30011
  "devDependencies": {
29713
- "@tanstack/react-router-devtools": "^1.141.1",
29714
- "@tanstack/router-plugin": "^1.141.1",
30012
+ "@tanstack/react-router-devtools": "^1.166.13",
30013
+ "@tanstack/router-plugin": "^1.167.22",
29715
30014
  "@types/node": "^22.13.14",
29716
- "@types/react": "^19.2.10",
30015
+ "@types/react": "^19.2.14",
29717
30016
  "@types/react-dom": "^19.2.3",
29718
- "@vitejs/plugin-react": "^4.3.4",
29719
- "postcss": "^8.5.3",
29720
- "tailwindcss": "^4.1.18",
29721
- "vite": "^6.2.2"
30017
+ "@vitejs/plugin-react": "^6.0.1",
30018
+ "postcss": "^8.5.10",
30019
+ "tailwindcss": "^4.2.2",
30020
+ "vite": "^8.0.8"
29722
30021
  }
29723
30022
  }
29724
30023
  `],
@@ -29825,6 +30124,7 @@ function ClerkApiAuthBridge() {
29825
30124
  const router = createRouter({
29826
30125
  routeTree,
29827
30126
  defaultPreload: "intent",
30127
+ scrollRestoration: true,
29828
30128
  defaultPendingComponent: () => <Loader />,
29829
30129
  {{#if (eq api "orpc")}}
29830
30130
  context: { orpc, queryClient },
@@ -30106,7 +30406,6 @@ function HomeComponent() {
30106
30406
  "target": "ESNext",
30107
30407
  "module": "ESNext",
30108
30408
  "moduleResolution": "Bundler",
30109
- "verbatimModuleSyntax": true,
30110
30409
  "skipLibCheck": true,
30111
30410
  "types": ["vite/client"],
30112
30411
  "rootDirs": ["."],
@@ -30121,24 +30420,25 @@ function HomeComponent() {
30121
30420
  ["frontend/react/tanstack-router/vite.config.ts.hbs", `import tailwindcss from "@tailwindcss/vite";
30122
30421
  import { tanstackRouter } from "@tanstack/router-plugin/vite";
30123
30422
  import react from "@vitejs/plugin-react";
30124
- import path from "node:path";
30125
30423
  import { defineConfig } from "vite";
30126
30424
 
30127
30425
  export default defineConfig({
30426
+ server: {
30427
+ port: 3001,
30428
+ },
30429
+ resolve: {
30430
+ tsconfigPaths: true,
30431
+ },
30128
30432
  plugins: [
30129
30433
  tailwindcss(),
30130
- tanstackRouter({}),
30434
+ tanstackRouter({
30435
+ target: "react",
30436
+ autoCodeSplitting: true,
30437
+ }),
30131
30438
  react(),
30132
30439
  ],
30133
- resolve: {
30134
- alias: {
30135
- "@": path.resolve(__dirname, "./src"),
30136
- },
30137
- },
30138
- server: {
30139
- port: 3001,
30140
- },
30141
- });`],
30440
+ });
30441
+ `],
30142
30442
  ["frontend/react/tanstack-start/package.json.hbs", `{
30143
30443
  "name": "web",
30144
30444
  "private": true,
@@ -30150,30 +30450,27 @@ export default defineConfig({
30150
30450
  },
30151
30451
  "dependencies": {
30152
30452
  "@{{projectName}}/ui": "{{#if (eq packageManager "npm")}}*{{else}}workspace:*{{/if}}",
30153
- "@tailwindcss/vite": "^4.1.18",
30154
- "@tanstack/react-query": "^5.80.6",
30155
- "@tanstack/react-router": "^1.141.1",
30156
- "@tanstack/react-router-with-query": "^1.130.17",
30157
- "@tanstack/react-start": "^1.141.1",
30158
- "@tanstack/router-plugin": "^1.141.1",
30159
- "lucide-react": "^0.546.0",
30453
+ "@tailwindcss/vite": "^4.2.2",
30454
+ "@tanstack/react-query": "^5.99.0",
30455
+ "@tanstack/react-router": "^1.168.22",
30456
+ "@tanstack/react-start": "^1.167.41",
30457
+ "lucide-react": "^1.8.0",
30160
30458
  "next-themes": "^0.4.6",
30161
- "react": "^19.2.3",
30162
- "react-dom": "^19.2.3",
30163
- "sonner": "^2.0.5",
30164
- "tailwindcss": "^4.1.18",
30165
- "vite-tsconfig-paths": "^5.1.4"
30459
+ "react": "^19.2.5",
30460
+ "react-dom": "^19.2.5",
30461
+ "sonner": "^2.0.7",
30462
+ "tailwindcss": "^4.2.2"
30166
30463
  },
30167
30464
  "devDependencies": {
30168
- "@tanstack/react-router-devtools": "^1.141.1",
30169
- "@testing-library/dom": "^10.4.0",
30170
- "@testing-library/react": "^16.2.0",
30171
- "@types/react": "^19.2.10",
30465
+ "@tanstack/react-router-devtools": "^1.166.13",
30466
+ "@testing-library/dom": "^10.4.1",
30467
+ "@testing-library/react": "^16.3.2",
30468
+ "@types/react": "^19.2.14",
30172
30469
  "@types/react-dom": "^19.2.3",
30173
- "@vitejs/plugin-react": "^5.0.4",
30174
- "jsdom": "^26.0.0",
30175
- "vite": "^7.0.2",
30176
- "web-vitals": "^5.0.3"
30470
+ "@vitejs/plugin-react": "^6.0.1",
30471
+ "jsdom": "^29.0.2",
30472
+ "vite": "^8.0.8",
30473
+ "web-vitals": "^5.2.0"
30177
30474
  }
30178
30475
  }
30179
30476
  `],
@@ -30196,7 +30493,8 @@ import Loader from "./components/loader";
30196
30493
  import "./index.css";
30197
30494
  import { routeTree } from "./routeTree.gen";
30198
30495
  {{#if (eq api "trpc")}}
30199
- import { QueryCache, QueryClient, QueryClientProvider } from "@tanstack/react-query";
30496
+ import { QueryCache, QueryClient } from "@tanstack/react-query";
30497
+ import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
30200
30498
  import { createTRPCClient, httpBatchLink } from "@trpc/client";
30201
30499
  import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
30202
30500
  import { toast } from "sonner";
@@ -30209,7 +30507,7 @@ import { env } from "@{{projectName}}/env/web";
30209
30507
  import { getClerkAuthToken } from "@/utils/clerk-auth";
30210
30508
  {{/if}}
30211
30509
  {{else if (eq api "orpc")}}
30212
- import { QueryClientProvider } from "@tanstack/react-query";
30510
+ import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
30213
30511
  import { orpc, queryClient } from "./utils/orpc";
30214
30512
  {{/if}}
30215
30513
  {{/if}}
@@ -30309,22 +30607,20 @@ export const getRouter = () => {
30309
30607
  defaultNotFoundComponent: () => <div>Not Found</div>,
30310
30608
  {{#if (eq api "trpc")}}
30311
30609
  Wrap: ({ children }) => (
30312
- <QueryClientProvider client={queryClient}>
30313
- <TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
30314
- {children}
30315
- </TRPCProvider>
30316
- </QueryClientProvider>
30317
- ),
30318
- {{else if (eq api "orpc")}}
30319
- Wrap: ({ children }) => (
30320
- <QueryClientProvider client={queryClient}>
30610
+ <TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
30321
30611
  {children}
30322
- </QueryClientProvider>
30612
+ </TRPCProvider>
30323
30613
  ),
30324
- {{else}}
30325
- Wrap: ({ children }) => <>{children}</>,
30326
30614
  {{/if}}
30327
30615
  });
30616
+ {{#if (or (eq api "trpc") (eq api "orpc"))}}
30617
+
30618
+ setupRouterSsrQueryIntegration({
30619
+ router,
30620
+ queryClient,
30621
+ });
30622
+ {{/if}}
30623
+
30328
30624
  return router;
30329
30625
  };
30330
30626
  {{/if}}
@@ -30689,7 +30985,6 @@ function HomeComponent() {
30689
30985
  /* Bundler mode */
30690
30986
  "moduleResolution": "bundler",
30691
30987
  "allowImportingTsExtensions": true,
30692
- "verbatimModuleSyntax": true,
30693
30988
  "noEmit": true,
30694
30989
 
30695
30990
  /* Linting */
@@ -30708,21 +31003,22 @@ function HomeComponent() {
30708
31003
  }
30709
31004
  `],
30710
31005
  ["frontend/react/tanstack-start/vite.config.ts.hbs", `import { defineConfig } from "vite";
30711
- import tsconfigPaths from "vite-tsconfig-paths";
30712
31006
  import { tanstackStart } from "@tanstack/react-start/plugin/vite";
30713
31007
  import tailwindcss from "@tailwindcss/vite";
30714
31008
  import viteReact from "@vitejs/plugin-react";
30715
31009
 
30716
31010
  export default defineConfig({
31011
+ server: {
31012
+ port: 3001,
31013
+ },
31014
+ resolve: {
31015
+ tsconfigPaths: true,
31016
+ },
30717
31017
  plugins: [
30718
- tsconfigPaths(),
30719
31018
  tailwindcss(),
30720
31019
  tanstackStart(),
30721
31020
  viteReact(),
30722
31021
  ],
30723
- server: {
30724
- port: 3001,
30725
- },
30726
31022
  {{#if (and (eq backend "convex") (eq auth "better-auth"))}}
30727
31023
  ssr: {
30728
31024
  noExternal: ["@convex-dev/better-auth"],
@@ -30946,16 +31242,16 @@ dist-ssr
30946
31242
  "test": "vitest run"
30947
31243
  },
30948
31244
  "dependencies": {
30949
- "@tailwindcss/vite": "^4.1.13",
30950
- "@tanstack/router-plugin": "^1.131.44",
30951
- "@tanstack/solid-router": "^1.131.44",
30952
- "lucide-solid": "^0.544.0",
30953
- "solid-js": "^1.9.9",
30954
- "tailwindcss": "^4.1.13"
31245
+ "@tailwindcss/vite": "^4.2.2",
31246
+ "@tanstack/router-plugin": "^1.167.22",
31247
+ "@tanstack/solid-router": "^1.168.20",
31248
+ "lucide-solid": "^1.8.0",
31249
+ "solid-js": "^1.9.12",
31250
+ "tailwindcss": "^4.2.2"
30955
31251
  },
30956
31252
  "devDependencies": {
30957
- "vite": "^7.1.5",
30958
- "vite-plugin-solid": "^2.11.8"
31253
+ "vite": "^8.0.8",
31254
+ "vite-plugin-solid": "^2.11.12"
30959
31255
  }
30960
31256
  }
30961
31257
  `],
@@ -31260,14 +31556,14 @@ vite.config.ts.timestamp-*
31260
31556
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
31261
31557
  },
31262
31558
  "devDependencies": {
31263
- "@sveltejs/adapter-auto": "^6.1.0",
31264
- "@sveltejs/kit": "^2.31.1",
31265
- "@sveltejs/vite-plugin-svelte": "^6.1.2",
31266
- "@tailwindcss/vite": "^4.1.12",
31267
- "svelte": "^5.38.1",
31268
- "svelte-check": "^4.3.1",
31269
- "tailwindcss": "^4.1.12",
31270
- "vite": "^7.1.2"
31559
+ "@sveltejs/adapter-auto": "^7.0.1",
31560
+ "@sveltejs/kit": "^2.57.1",
31561
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
31562
+ "@tailwindcss/vite": "^4.2.2",
31563
+ "svelte": "^5.55.4",
31564
+ "svelte-check": "^4.4.6",
31565
+ "tailwindcss": "^4.2.2",
31566
+ "vite": "^8.0.8"
31271
31567
  },
31272
31568
  "dependencies": {}
31273
31569
  }
@@ -31613,7 +31909,69 @@ export const env = createEnv({
31613
31909
  emptyStringAsUndefined: true,
31614
31910
  });
31615
31911
  `],
31616
- ["packages/env/src/server.ts.hbs", `{{#if (or (eq serverDeploy "cloudflare") (and (eq backend "self") (eq webDeploy "cloudflare")))}}
31912
+ ["packages/env/src/server.ts.hbs", `{{#if (eq serverDeploy "cloudflare")}}
31913
+ /// <reference path="../env.d.ts" />
31914
+ // For Cloudflare Workers, env is accessed via cloudflare:workers module
31915
+ // Types are defined in env.d.ts based on your alchemy.run.ts bindings
31916
+ export { env } from "cloudflare:workers";
31917
+ {{else if (and (eq backend "self") (eq webDeploy "cloudflare") (includes frontend "next"))}}
31918
+ /// <reference path="../env.d.ts" />
31919
+ import { getCloudflareContext } from "@opennextjs/cloudflare";
31920
+
31921
+ function getNodeEnvValue(key: string) {
31922
+ return process.env[key];
31923
+ }
31924
+
31925
+ function getCloudflareEnvSync() {
31926
+ try {
31927
+ return getCloudflareContext().env as Env;
31928
+ } catch {
31929
+ return undefined;
31930
+ }
31931
+ }
31932
+
31933
+ type EnvValue = Env[keyof Env];
31934
+
31935
+ function createEnvProxy(getValue: (key: keyof Env & string) => EnvValue | undefined) {
31936
+ return new Proxy({} as Env, {
31937
+ get(_target, prop) {
31938
+ if (typeof prop !== "string") {
31939
+ return undefined;
31940
+ }
31941
+
31942
+ return getValue(prop as keyof Env & string);
31943
+ },
31944
+ });
31945
+ }
31946
+
31947
+ function resolveEnvValue(key: keyof Env & string): EnvValue | undefined {
31948
+ const nodeValue = getNodeEnvValue(key);
31949
+ if (nodeValue !== undefined) {
31950
+ return nodeValue as EnvValue;
31951
+ }
31952
+
31953
+ return getCloudflareEnvSync()?.[key as keyof Env];
31954
+ }
31955
+
31956
+ // Next.js local dev runs in Node.js, where env vars are exposed on process.env.
31957
+ // In the Cloudflare runtime, fall back to OpenNext's Cloudflare context bindings.
31958
+ // For static routes (ISR/SSG), use getEnvAsync() so OpenNext can resolve bindings
31959
+ // with the async Cloudflare context API.
31960
+ export async function getEnvAsync() {
31961
+ const cloudflareEnv = (await getCloudflareContext({ async: true })).env as Env;
31962
+
31963
+ return createEnvProxy((key) => {
31964
+ const nodeValue = getNodeEnvValue(key);
31965
+ if (nodeValue !== undefined) {
31966
+ return nodeValue;
31967
+ }
31968
+
31969
+ return cloudflareEnv[key as keyof Env];
31970
+ });
31971
+ }
31972
+
31973
+ export const env = createEnvProxy(resolveEnvValue);
31974
+ {{else if (and (eq backend "self") (eq webDeploy "cloudflare"))}}
31617
31975
  /// <reference path="../env.d.ts" />
31618
31976
  // For Cloudflare Workers, env is accessed via cloudflare:workers module
31619
31977
  // Types are defined in env.d.ts based on your alchemy.run.ts bindings