create-better-t-stack 3.11.0 → 3.12.0

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 (71) hide show
  1. package/dist/chunk-Dt3mZKp0.mjs +24 -0
  2. package/dist/cli.mjs +1 -1
  3. package/dist/index.d.mts +40 -60
  4. package/dist/index.mjs +2 -2
  5. package/dist/{src-XVvJUQ_h.mjs → src-DBVnwTkj.mjs} +668 -631
  6. package/package.json +2 -2
  7. package/templates/addons/turborepo/turbo.json.hbs +13 -0
  8. package/templates/api/orpc/native/utils/orpc.ts.hbs +21 -20
  9. package/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs +3 -5
  10. package/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs +73 -67
  11. package/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs +15 -14
  12. package/templates/api/trpc/native/utils/trpc.ts.hbs +8 -7
  13. package/templates/api/trpc/web/react/base/src/utils/trpc.ts.hbs +59 -57
  14. package/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs +3 -5
  15. package/templates/auth/better-auth/convex/backend/convex/privateData.ts.hbs +13 -12
  16. package/templates/auth/better-auth/convex/native/base/lib/auth-client.ts.hbs +10 -9
  17. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-client.ts.hbs +2 -2
  18. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-server.ts.hbs +11 -9
  19. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs +5 -4
  20. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs +8 -7
  21. package/templates/auth/better-auth/native/base/lib/auth-client.ts.hbs +9 -8
  22. package/templates/auth/better-auth/server/base/src/index.ts.hbs +239 -235
  23. package/templates/auth/better-auth/web/nuxt/app/plugins/auth-client.ts.hbs +2 -3
  24. package/templates/auth/better-auth/web/react/base/src/lib/auth-client.ts.hbs +9 -11
  25. package/templates/auth/better-auth/web/solid/src/lib/auth-client.ts.hbs +3 -2
  26. package/templates/backend/server/elysia/src/index.ts.hbs +71 -71
  27. package/templates/backend/server/express/src/index.ts.hbs +57 -57
  28. package/templates/backend/server/fastify/src/index.ts.hbs +107 -107
  29. package/templates/backend/server/hono/src/index.ts.hbs +75 -85
  30. package/templates/base/tsconfig.json.hbs +3 -0
  31. package/templates/db/drizzle/mysql/src/index.ts.hbs +23 -30
  32. package/templates/db/drizzle/postgres/src/index.ts.hbs +6 -13
  33. package/templates/db/drizzle/sqlite/src/index.ts.hbs +11 -18
  34. package/templates/db/mongoose/mongodb/src/index.ts.hbs +3 -2
  35. package/templates/db/prisma/mongodb/prisma/schema/schema.prisma.hbs +1 -1
  36. package/templates/db/prisma/mysql/prisma/schema/schema.prisma.hbs +1 -1
  37. package/templates/db/prisma/mysql/prisma.config.ts.hbs +16 -16
  38. package/templates/db/prisma/mysql/src/index.ts.hbs +16 -15
  39. package/templates/db/prisma/postgres/prisma/schema/schema.prisma.hbs +1 -1
  40. package/templates/db/prisma/postgres/src/index.ts.hbs +10 -9
  41. package/templates/db/prisma/sqlite/prisma/schema/schema.prisma.hbs +1 -1
  42. package/templates/db/prisma/sqlite/src/index.ts.hbs +4 -7
  43. package/templates/examples/ai/native/bare/app/(drawer)/ai.tsx.hbs +2 -1
  44. package/templates/examples/ai/native/unistyles/app/(drawer)/ai.tsx.hbs +2 -1
  45. package/templates/examples/ai/native/uniwind/app/(drawer)/ai.tsx.hbs +2 -1
  46. package/templates/examples/ai/web/nuxt/app/pages/ai.vue.hbs +1 -3
  47. package/templates/examples/ai/web/react/next/src/app/ai/page.tsx.hbs +4 -3
  48. package/templates/examples/ai/web/react/react-router/src/routes/ai.tsx.hbs +2 -1
  49. package/templates/examples/ai/web/react/tanstack-router/src/routes/ai.tsx.hbs +4 -1
  50. package/templates/examples/ai/web/react/tanstack-start/src/routes/ai.tsx.hbs +4 -1
  51. package/templates/frontend/native/bare/app/_layout.tsx.hbs +4 -2
  52. package/templates/frontend/native/unistyles/app/_layout.tsx.hbs +4 -2
  53. package/templates/frontend/native/uniwind/app/_layout.tsx.hbs +4 -3
  54. package/templates/frontend/nuxt/nuxt.config.ts.hbs +6 -3
  55. package/templates/frontend/react/next/next.config.ts.hbs +9 -8
  56. package/templates/frontend/react/next/src/components/providers.tsx.hbs +4 -1
  57. package/templates/frontend/react/next/tsconfig.json.hbs +2 -2
  58. package/templates/frontend/react/react-router/src/root.tsx.hbs +3 -4
  59. package/templates/frontend/react/tanstack-router/src/main.tsx.hbs +3 -2
  60. package/templates/frontend/react/tanstack-start/src/router.tsx.hbs +100 -108
  61. package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +25 -7
  62. package/templates/packages/config/tsconfig.base.json.hbs +1 -1
  63. package/templates/{deploy/alchemy → packages/env}/env.d.ts.hbs +6 -4
  64. package/templates/packages/env/package.json.hbs +7 -0
  65. package/templates/packages/env/src/native.ts.hbs +21 -0
  66. package/templates/packages/env/src/server.ts.hbs +38 -0
  67. package/templates/packages/env/src/web.ts.hbs +89 -0
  68. package/templates/packages/env/tsconfig.json.hbs +3 -0
  69. package/templates/{deploy/alchemy → packages/infra}/alchemy.run.ts.hbs +86 -82
  70. package/templates/packages/infra/package.json.hbs +10 -0
  71. package/templates/payments/polar/server/base/src/lib/payments.ts.hbs +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
5
  "keywords": [
6
6
  "better-auth",
@@ -67,7 +67,7 @@
67
67
  "prepublishOnly": "npm run build"
68
68
  },
69
69
  "dependencies": {
70
- "@better-t-stack/types": "^3.11.0",
70
+ "@better-t-stack/types": "^3.12.0",
71
71
  "@clack/prompts": "^1.0.0-alpha.8",
72
72
  "@orpc/server": "^1.13.0",
73
73
  "consola": "^3.4.2",
@@ -55,6 +55,19 @@
55
55
  "db:down": {
56
56
  "cache": false,
57
57
  "persistent": true
58
+ }{{/if}}
59
+ {{#if (and (eq database "sqlite") (ne dbSetup "d1"))}},
60
+ "db:local": {
61
+ "cache": false,
62
+ "persistent": true
63
+ }
64
+ {{/if}}
65
+ {{#if (or (eq webDeploy "cloudflare") (eq serverDeploy "cloudflare"))}},
66
+ "deploy": {
67
+ "cache": false
68
+ },
69
+ "destroy": {
70
+ "cache": false
58
71
  }
59
72
  {{/if}}
60
73
  }
@@ -3,34 +3,35 @@ import { RPCLink } from "@orpc/client/fetch";
3
3
  import { createTanstackQueryUtils } from "@orpc/tanstack-query";
4
4
  import { QueryCache, QueryClient } from "@tanstack/react-query";
5
5
  import type { AppRouterClient } from "@{{projectName}}/api/routers/index";
6
+ import { env } from "@{{projectName}}/env/native";
6
7
  {{#if (eq auth "better-auth")}}
7
8
  import { authClient } from "@/lib/auth-client";
8
9
  {{/if}}
9
10
 
10
11
  export const queryClient = new QueryClient({
11
- queryCache: new QueryCache({
12
- onError: (error) => {
13
- console.log(error)
14
- },
15
- }),
12
+ queryCache: new QueryCache({
13
+ onError: (error) => {
14
+ console.log(error)
15
+ },
16
+ }),
16
17
  });
17
18
 
18
19
  export const link = new RPCLink({
19
- {{#if (eq backend "self")}}
20
- url: `${process.env.EXPO_PUBLIC_SERVER_URL}/api/rpc`,
21
- {{else}}
22
- url: `${process.env.EXPO_PUBLIC_SERVER_URL}/rpc`,
23
- {{/if}}
24
- {{#if (eq auth "better-auth")}}
25
- headers() {
26
- const headers = new Map<string, string>();
27
- const cookies = authClient.getCookie();
28
- if (cookies) {
29
- headers.set("Cookie", cookies);
30
- }
31
- return Object.fromEntries(headers);
32
- },
33
- {{/if}}
20
+ {{#if (eq backend "self")}}
21
+ url: `${env.EXPO_PUBLIC_SERVER_URL}/api/rpc`,
22
+ {{else}}
23
+ url: `${env.EXPO_PUBLIC_SERVER_URL}/rpc`,
24
+ {{/if}}
25
+ {{#if (eq auth "better-auth")}}
26
+ headers() {
27
+ const headers = new Map<string, string>();
28
+ const cookies = authClient.getCookie();
29
+ if (cookies) {
30
+ headers.set("Cookie", cookies);
31
+ }
32
+ return Object.fromEntries(headers);
33
+ },
34
+ {{/if}}
34
35
  });
35
36
 
36
37
  export const client: AppRouterClient = createORPCClient(link);
@@ -1,14 +1,12 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from '#app'
1
+ import { defineNuxtPlugin } from '#app'
2
2
  import type { AppRouterClient } from "@{{projectName}}/api/routers/index";
3
3
  import { createORPCClient } from '@orpc/client'
4
4
  import { RPCLink } from '@orpc/client/fetch'
5
5
  import { createTanstackQueryUtils } from "@orpc/tanstack-query";
6
6
 
7
7
  export default defineNuxtPlugin(() => {
8
- const config = useRuntimeConfig()
9
- const serverUrl = config.public.serverURL
10
-
11
- const rpcUrl = `${serverUrl}/rpc`;
8
+ const config = useRuntimeConfig();
9
+ const rpcUrl = `${config.public.serverUrl}/rpc`;
12
10
 
13
11
  const rpcLink = new RPCLink({
14
12
  url: rpcUrl,
@@ -9,88 +9,94 @@ import type { RouterClient } from "@orpc/server";
9
9
  import { createIsomorphicFn } from "@tanstack/react-start";
10
10
  import { appRouter } from "@{{projectName}}/api/routers/index";
11
11
  import { createContext } from "@{{projectName}}/api/context";
12
+ {{#unless (eq backend "self")}}
13
+ import { env } from "@{{projectName}}/env/web";
14
+ {{/unless}}
12
15
  {{else}}
13
16
  import type { AppRouterClient } from "@{{projectName}}/api/routers/index";
17
+ {{#unless (eq backend "self")}}
18
+ import { env } from "@{{projectName}}/env/web";
19
+ {{/unless}}
14
20
  {{/if}}
15
21
 
16
22
  export const queryClient = new QueryClient({
17
- queryCache: new QueryCache({
18
- onError: (error, query) => {
19
- toast.error(`Error: ${error.message}`, {
20
- action: {
21
- label: "retry",
22
- onClick: query.invalidate,
23
- },
24
- });
25
- },
26
- }),
23
+ queryCache: new QueryCache({
24
+ onError: (error, query) => {
25
+ toast.error(`Error: ${error.message}`, {
26
+ action: {
27
+ label: "retry",
28
+ onClick: query.invalidate,
29
+ },
30
+ });
31
+ },
32
+ }),
27
33
  });
28
34
 
29
35
  {{#if (includes frontend "tanstack-start")}}
30
36
  const getORPCClient = createIsomorphicFn()
31
- .server(() =>
32
- createRouterClient(appRouter, {
33
- context: async ({ req }) => {
34
- {{#if (eq backend "self")}}
35
- return createContext({ req });
36
- {{else if (eq backend "hono")}}
37
- return createContext({ context: req });
38
- {{else if (eq backend "elysia")}}
39
- return createContext({ context: req });
40
- {{else if (eq backend "express")}}
41
- return createContext({ req });
42
- {{else if (eq backend "fastify")}}
43
- return createContext(req.headers);
44
- {{else}}
45
- return createContext();
46
- {{/if}}
47
- },
48
- }),
49
- )
50
- .client((): RouterClient<typeof appRouter> => {
51
- const link = new RPCLink({
52
- url: {{#if (eq backend "self")}}`${window.location.origin}/api/rpc`{{else}}`${import.meta.env.VITE_SERVER_URL}/rpc`{{/if}},
53
- {{#if (eq auth "better-auth")}}
54
- fetch(url, options) {
55
- return fetch(url, {
56
- ...options,
57
- credentials: "include",
58
- });
59
- },
60
- {{/if}}
61
- });
37
+ .server(() =>
38
+ createRouterClient(appRouter, {
39
+ context: async ({ req }) => {
40
+ {{#if (eq backend "self")}}
41
+ return createContext({ req });
42
+ {{else if (eq backend "hono")}}
43
+ return createContext({ context: req });
44
+ {{else if (eq backend "elysia")}}
45
+ return createContext({ context: req });
46
+ {{else if (eq backend "express")}}
47
+ return createContext({ req });
48
+ {{else if (eq backend "fastify")}}
49
+ return createContext(req.headers);
50
+ {{else}}
51
+ return createContext();
52
+ {{/if}}
53
+ },
54
+ }),
55
+ )
56
+ .client((): RouterClient<typeof appRouter> => {
57
+ const link = new RPCLink({
58
+ url: {{#if (eq backend "self")}}`${window.location.origin}/api/rpc`{{else}}`${env.VITE_SERVER_URL}/rpc`{{/if}},
59
+ {{#if (eq auth "better-auth")}}
60
+ fetch(url, options) {
61
+ return fetch(url, {
62
+ ...options,
63
+ credentials: "include",
64
+ });
65
+ },
66
+ {{/if}}
67
+ });
62
68
 
63
- return createORPCClient(link);
64
- });
69
+ return createORPCClient(link);
70
+ });
65
71
 
66
72
  export const client: RouterClient<typeof appRouter> = getORPCClient();
67
73
  {{else}}
68
74
  export const link = new RPCLink({
69
- {{#if (and (eq backend "self") (includes frontend "next"))}}
70
- url: `${typeof window !== "undefined" ? window.location.origin : "http://localhost:3001"}/api/rpc`,
71
- {{else if (includes frontend "next")}}
72
- url: `${process.env.NEXT_PUBLIC_SERVER_URL}/rpc`,
73
- {{else}}
74
- url: `${import.meta.env.VITE_SERVER_URL}/rpc`,
75
- {{/if}}
76
- {{#if (eq auth "better-auth")}}
77
- fetch(url, options) {
78
- return fetch(url, {
79
- ...options,
80
- credentials: "include",
81
- });
82
- },
83
- {{#if (includes frontend "next")}}
84
- headers: async () => {
85
- if (typeof window !== "undefined") {
86
- return {}
87
- }
75
+ {{#if (and (eq backend "self") (includes frontend "next"))}}
76
+ url: `${typeof window !== "undefined" ? window.location.origin : "http://localhost:3001"}/api/rpc`,
77
+ {{else if (includes frontend "next")}}
78
+ url: `${env.NEXT_PUBLIC_SERVER_URL}/rpc`,
79
+ {{else}}
80
+ url: `${env.VITE_SERVER_URL}/rpc`,
81
+ {{/if}}
82
+ {{#if (eq auth "better-auth")}}
83
+ fetch(url, options) {
84
+ return fetch(url, {
85
+ ...options,
86
+ credentials: "include",
87
+ });
88
+ },
89
+ {{#if (includes frontend "next")}}
90
+ headers: async () => {
91
+ if (typeof window !== "undefined") {
92
+ return {}
93
+ }
88
94
 
89
- const { headers } = await import("next/headers")
90
- return Object.fromEntries(await headers())
91
- },
92
- {{/if}}
93
- {{/if}}
95
+ const { headers } = await import("next/headers")
96
+ return Object.fromEntries(await headers())
97
+ },
98
+ {{/if}}
99
+ {{/if}}
94
100
  });
95
101
 
96
102
  export const client: AppRouterClient = createORPCClient(link)
@@ -3,25 +3,26 @@ import { RPCLink } from "@orpc/client/fetch";
3
3
  import { createTanstackQueryUtils } from "@orpc/tanstack-query";
4
4
  import { QueryCache, QueryClient } from "@tanstack/solid-query";
5
5
  import type { AppRouterClient } from "@{{projectName}}/api/routers/index";
6
+ import { env } from "@{{projectName}}/env/web";
6
7
 
7
8
  export const queryClient = new QueryClient({
8
- queryCache: new QueryCache({
9
- onError: (error) => {
10
- console.error(`Error: ${error.message}`);
11
- },
12
- }),
9
+ queryCache: new QueryCache({
10
+ onError: (error) => {
11
+ console.error(`Error: ${error.message}`);
12
+ },
13
+ }),
13
14
  });
14
15
 
15
16
  export const link = new RPCLink({
16
- url: `${import.meta.env.VITE_SERVER_URL}/rpc`,
17
- {{#if (eq auth "better-auth")}}
18
- fetch(url, options) {
19
- return fetch(url, {
20
- ...options,
21
- credentials: "include",
22
- });
23
- },
24
- {{/if}}
17
+ url: `${env.VITE_SERVER_URL}/rpc`,
18
+ {{#if (eq auth "better-auth")}}
19
+ fetch(url, options) {
20
+ return fetch(url, {
21
+ ...options,
22
+ credentials: "include",
23
+ });
24
+ },
25
+ {{/if}}
25
26
  });
26
27
 
27
28
  export const client: AppRouterClient = createORPCClient(link);
@@ -5,18 +5,19 @@ import { QueryClient } from "@tanstack/react-query";
5
5
  import { createTRPCClient, httpBatchLink } from "@trpc/client";
6
6
  import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
7
7
  import type { AppRouter } from "@{{projectName}}/api/routers/index";
8
+ import { env } from "@{{projectName}}/env/native";
8
9
 
9
10
  export const queryClient = new QueryClient();
10
11
 
11
12
  const trpcClient = createTRPCClient<AppRouter>({
12
13
  links: [
13
14
  httpBatchLink({
14
- {{#if (eq backend "self")}}
15
- url: `${process.env.EXPO_PUBLIC_SERVER_URL}/api/trpc`,
16
- {{else}}
17
- url: `${process.env.EXPO_PUBLIC_SERVER_URL}/trpc`,
18
- {{/if}}
19
- {{#if (eq auth "better-auth")}}
15
+ {{#if (eq backend "self")}}
16
+ url: `${env.EXPO_PUBLIC_SERVER_URL}/api/trpc`,
17
+ {{else}}
18
+ url: `${env.EXPO_PUBLIC_SERVER_URL}/trpc`,
19
+ {{/if}}
20
+ {{#if (eq auth "better-auth")}}
20
21
  headers() {
21
22
  const headers = new Map<string, string>();
22
23
  const cookies = authClient.getCookie();
@@ -25,7 +26,7 @@ const trpcClient = createTRPCClient<AppRouter>({
25
26
  }
26
27
  return Object.fromEntries(headers);
27
28
  },
28
- {{/if}}
29
+ {{/if}}
29
30
  }),
30
31
  ],
31
32
  });
@@ -4,45 +4,46 @@ import { createTRPCClient, httpBatchLink } from '@trpc/client';
4
4
  import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
5
5
  import type { AppRouter } from "@{{projectName}}/api/routers/index";
6
6
  import { toast } from 'sonner';
7
+ {{#unless (eq backend "self")}}
8
+ import { env } from "@{{projectName}}/env/web";
9
+ {{/unless}}
7
10
 
8
11
  export const queryClient = new QueryClient({
9
- queryCache: new QueryCache({
10
- onError: (error, query) => {
11
- toast.error(error.message, {
12
- action: {
13
- label: "retry",
14
- onClick: query.invalidate,
15
- },
16
- });
17
- },
18
- }),
12
+ queryCache: new QueryCache({
13
+ onError: (error, query) => {
14
+ toast.error(error.message, {
15
+ action: {
16
+ label: "retry",
17
+ onClick: query.invalidate,
18
+ },
19
+ });
20
+ },
21
+ }),
19
22
  });
20
23
 
21
24
  const trpcClient = createTRPCClient<AppRouter>({
22
- links: [
23
- httpBatchLink({
24
- {{#if (and (eq backend "self") (includes frontend 'next'))}}
25
- url: "/api/trpc",
26
- {{else if (includes frontend 'next')}}
27
- url: `${process.env.NEXT_PUBLIC_SERVER_URL}/trpc`,
28
- {{else}}
29
- url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
30
- {{/if}}
31
- {{#if (eq auth "better-auth")}}
32
- fetch(url, options) {
33
- return fetch(url, {
34
- ...options,
35
- credentials: "include",
36
- });
37
- },
38
- {{/if}}
39
- }),
40
- ],
25
+ links: [
26
+ httpBatchLink({
27
+ {{#if (eq backend "self")}}
28
+ url: "/api/trpc",
29
+ {{else}}
30
+ url: `${env.NEXT_PUBLIC_SERVER_URL}/trpc`,
31
+ {{/if}}
32
+ {{#if (eq auth "better-auth")}}
33
+ fetch(url, options) {
34
+ return fetch(url, {
35
+ ...options,
36
+ credentials: "include",
37
+ });
38
+ },
39
+ {{/if}}
40
+ }),
41
+ ],
41
42
  })
42
43
 
43
44
  export const trpc = createTRPCOptionsProxy<AppRouter>({
44
- client: trpcClient,
45
- queryClient,
45
+ client: trpcClient,
46
+ queryClient,
46
47
  });
47
48
 
48
49
  {{else if (includes frontend 'tanstack-start')}}
@@ -50,7 +51,7 @@ import { createTRPCContext } from "@trpc/tanstack-react-query";
50
51
  import type { AppRouter } from "@{{projectName}}/api/routers/index";
51
52
 
52
53
  export const { TRPCProvider, useTRPC, useTRPCClient } =
53
- createTRPCContext<AppRouter>();
54
+ createTRPCContext<AppRouter>();
54
55
 
55
56
  {{else}}
56
57
  import type { AppRouter } from "@{{projectName}}/api/routers/index";
@@ -58,38 +59,39 @@ import { QueryCache, QueryClient } from "@tanstack/react-query";
58
59
  import { createTRPCClient, httpBatchLink } from "@trpc/client";
59
60
  import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
60
61
  import { toast } from "sonner";
62
+ import { env } from "@{{projectName}}/env/web";
61
63
 
62
64
  export const queryClient = new QueryClient({
63
- queryCache: new QueryCache({
64
- onError: (error, query) => {
65
- toast.error(error.message, {
66
- action: {
67
- label: "retry",
68
- onClick: query.invalidate,
69
- },
70
- });
71
- },
72
- }),
65
+ queryCache: new QueryCache({
66
+ onError: (error, query) => {
67
+ toast.error(error.message, {
68
+ action: {
69
+ label: "retry",
70
+ onClick: query.invalidate,
71
+ },
72
+ });
73
+ },
74
+ }),
73
75
  });
74
76
 
75
77
  export const trpcClient = createTRPCClient<AppRouter>({
76
- links: [
77
- httpBatchLink({
78
- url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
79
- {{#if (eq auth "better-auth")}}
80
- fetch(url, options) {
81
- return fetch(url, {
82
- ...options,
83
- credentials: "include",
84
- });
85
- },
86
- {{/if}}
87
- }),
88
- ],
78
+ links: [
79
+ httpBatchLink({
80
+ url: `${env.VITE_SERVER_URL}/trpc`,
81
+ {{#if (eq auth "better-auth")}}
82
+ fetch(url, options) {
83
+ return fetch(url, {
84
+ ...options,
85
+ credentials: "include",
86
+ });
87
+ },
88
+ {{/if}}
89
+ }),
90
+ ],
89
91
  });
90
92
 
91
93
  export const trpc = createTRPCOptionsProxy<AppRouter>({
92
- client: trpcClient,
93
- queryClient,
94
+ client: trpcClient,
95
+ queryClient,
94
96
  });
95
97
  {{/if}}
@@ -8,10 +8,9 @@ import { convex, crossDomain } from "@convex-dev/better-auth/plugins";
8
8
  import { convex } from "@convex-dev/better-auth/plugins";
9
9
  {{/if}}
10
10
  import { components } from "./_generated/api";
11
- import { DataModel } from "./_generated/dataModel";
11
+ import type { DataModel } from "./_generated/dataModel";
12
12
  import { query } from "./_generated/server";
13
13
  import { betterAuth } from "better-auth";
14
- import { v } from "convex/values";
15
14
  import authConfig from "./auth.config";
16
15
 
17
16
  {{#if (or (includes frontend "tanstack-start") (includes frontend "next"))}}
@@ -63,8 +62,7 @@ export { createAuth };
63
62
 
64
63
  export const getCurrentUser = query({
65
64
  args: {},
66
- returns: v.any(),
67
- handler: async function (ctx) {
68
- return authComponent.getAuthUser(ctx);
65
+ handler: async (ctx) => {
66
+ return await authComponent.safeGetAuthUser(ctx);
69
67
  },
70
68
  });
@@ -1,16 +1,17 @@
1
1
  import { query } from "./_generated/server";
2
+ import { authComponent } from "./auth";
2
3
 
3
4
  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
- },
5
+ args: {},
6
+ handler: async (ctx) => {
7
+ const authUser = await authComponent.safeGetAuthUser(ctx);
8
+ if (!authUser) {
9
+ return {
10
+ message: "Not authenticated",
11
+ };
12
+ }
13
+ return {
14
+ message: "This is private",
15
+ };
16
+ },
16
17
  });
@@ -3,15 +3,16 @@ import { convexClient } from "@convex-dev/better-auth/client/plugins";
3
3
  import { expoClient } from "@better-auth/expo/client";
4
4
  import Constants from "expo-constants";
5
5
  import * as SecureStore from "expo-secure-store";
6
+ import { env } from "@{{projectName}}/env/native";
6
7
 
7
8
  export const authClient = createAuthClient({
8
- baseURL: process.env.EXPO_PUBLIC_CONVEX_SITE_URL,
9
- plugins: [
10
- expoClient({
11
- scheme: Constants.expoConfig?.scheme as string,
12
- storagePrefix: Constants.expoConfig?.scheme as string,
13
- storage: SecureStore,
14
- }),
15
- convexClient(),
16
- ],
9
+ baseURL: env.EXPO_PUBLIC_CONVEX_SITE_URL,
10
+ plugins: [
11
+ expoClient({
12
+ scheme: Constants.expoConfig?.scheme as string,
13
+ storagePrefix: Constants.expoConfig?.scheme as string,
14
+ storage: SecureStore,
15
+ }),
16
+ convexClient(),
17
+ ],
17
18
  });
@@ -2,5 +2,5 @@ import { createAuthClient } from "better-auth/react";
2
2
  import { convexClient } from "@convex-dev/better-auth/client/plugins";
3
3
 
4
4
  export const authClient = createAuthClient({
5
- plugins: [convexClient()],
6
- });
5
+ plugins: [convexClient()],
6
+ });
@@ -1,14 +1,16 @@
1
1
  import { convexBetterAuthNextJs } from "@convex-dev/better-auth/nextjs";
2
+ import { isAuthError } from "@/lib/utils";
3
+ import { env } from "@{{projectName}}/env/web";
2
4
 
3
5
  export const {
4
- handler,
5
- preloadAuthQuery,
6
- isAuthenticated,
7
- getToken,
8
- fetchAuthQuery,
9
- fetchAuthMutation,
10
- fetchAuthAction,
6
+ handler,
7
+ preloadAuthQuery,
8
+ isAuthenticated,
9
+ getToken,
10
+ fetchAuthQuery,
11
+ fetchAuthMutation,
12
+ fetchAuthAction,
11
13
  } = convexBetterAuthNextJs({
12
- convexUrl: process.env.NEXT_PUBLIC_CONVEX_URL!,
13
- convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
14
+ convexUrl: env.NEXT_PUBLIC_CONVEX_URL,
15
+ convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
14
16
  });
@@ -1,10 +1,11 @@
1
1
  import { createAuthClient } from "better-auth/react";
2
2
  import {
3
- convexClient,
4
- crossDomainClient,
3
+ convexClient,
4
+ crossDomainClient,
5
5
  } from "@convex-dev/better-auth/client/plugins";
6
+ import { env } from "@{{projectName}}/env/web";
6
7
 
7
8
  export const authClient = createAuthClient({
8
- baseURL: import.meta.env.VITE_CONVEX_SITE_URL,
9
- plugins: [convexClient(), crossDomainClient()],
9
+ baseURL: env.VITE_CONVEX_SITE_URL,
10
+ plugins: [convexClient(), crossDomainClient()],
10
11
  });
@@ -1,12 +1,13 @@
1
1
  import { convexBetterAuthReactStart } from "@convex-dev/better-auth/react-start";
2
+ import { env } from "@{{projectName}}/env/web";
2
3
 
3
4
  export const {
4
- handler,
5
- getToken,
6
- fetchAuthQuery,
7
- fetchAuthMutation,
8
- fetchAuthAction,
5
+ handler,
6
+ getToken,
7
+ fetchAuthQuery,
8
+ fetchAuthMutation,
9
+ fetchAuthAction,
9
10
  } = convexBetterAuthReactStart({
10
- convexUrl: process.env.VITE_CONVEX_URL!,
11
- convexSiteUrl: process.env.VITE_CONVEX_SITE_URL!,
11
+ convexUrl: env.VITE_CONVEX_URL,
12
+ convexSiteUrl: env.VITE_CONVEX_SITE_URL,
12
13
  });