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.
- package/dist/chunk-Dt3mZKp0.mjs +24 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +40 -60
- package/dist/index.mjs +2 -2
- package/dist/{src-XVvJUQ_h.mjs → src-DBVnwTkj.mjs} +668 -631
- package/package.json +2 -2
- package/templates/addons/turborepo/turbo.json.hbs +13 -0
- package/templates/api/orpc/native/utils/orpc.ts.hbs +21 -20
- package/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs +3 -5
- package/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs +73 -67
- package/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs +15 -14
- package/templates/api/trpc/native/utils/trpc.ts.hbs +8 -7
- package/templates/api/trpc/web/react/base/src/utils/trpc.ts.hbs +59 -57
- package/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs +3 -5
- package/templates/auth/better-auth/convex/backend/convex/privateData.ts.hbs +13 -12
- package/templates/auth/better-auth/convex/native/base/lib/auth-client.ts.hbs +10 -9
- package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-client.ts.hbs +2 -2
- package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-server.ts.hbs +11 -9
- package/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs +5 -4
- package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs +8 -7
- package/templates/auth/better-auth/native/base/lib/auth-client.ts.hbs +9 -8
- package/templates/auth/better-auth/server/base/src/index.ts.hbs +239 -235
- package/templates/auth/better-auth/web/nuxt/app/plugins/auth-client.ts.hbs +2 -3
- package/templates/auth/better-auth/web/react/base/src/lib/auth-client.ts.hbs +9 -11
- package/templates/auth/better-auth/web/solid/src/lib/auth-client.ts.hbs +3 -2
- package/templates/backend/server/elysia/src/index.ts.hbs +71 -71
- package/templates/backend/server/express/src/index.ts.hbs +57 -57
- package/templates/backend/server/fastify/src/index.ts.hbs +107 -107
- package/templates/backend/server/hono/src/index.ts.hbs +75 -85
- package/templates/base/tsconfig.json.hbs +3 -0
- package/templates/db/drizzle/mysql/src/index.ts.hbs +23 -30
- package/templates/db/drizzle/postgres/src/index.ts.hbs +6 -13
- package/templates/db/drizzle/sqlite/src/index.ts.hbs +11 -18
- package/templates/db/mongoose/mongodb/src/index.ts.hbs +3 -2
- package/templates/db/prisma/mongodb/prisma/schema/schema.prisma.hbs +1 -1
- package/templates/db/prisma/mysql/prisma/schema/schema.prisma.hbs +1 -1
- package/templates/db/prisma/mysql/prisma.config.ts.hbs +16 -16
- package/templates/db/prisma/mysql/src/index.ts.hbs +16 -15
- package/templates/db/prisma/postgres/prisma/schema/schema.prisma.hbs +1 -1
- package/templates/db/prisma/postgres/src/index.ts.hbs +10 -9
- package/templates/db/prisma/sqlite/prisma/schema/schema.prisma.hbs +1 -1
- package/templates/db/prisma/sqlite/src/index.ts.hbs +4 -7
- package/templates/examples/ai/native/bare/app/(drawer)/ai.tsx.hbs +2 -1
- package/templates/examples/ai/native/unistyles/app/(drawer)/ai.tsx.hbs +2 -1
- package/templates/examples/ai/native/uniwind/app/(drawer)/ai.tsx.hbs +2 -1
- package/templates/examples/ai/web/nuxt/app/pages/ai.vue.hbs +1 -3
- package/templates/examples/ai/web/react/next/src/app/ai/page.tsx.hbs +4 -3
- package/templates/examples/ai/web/react/react-router/src/routes/ai.tsx.hbs +2 -1
- package/templates/examples/ai/web/react/tanstack-router/src/routes/ai.tsx.hbs +4 -1
- package/templates/examples/ai/web/react/tanstack-start/src/routes/ai.tsx.hbs +4 -1
- package/templates/frontend/native/bare/app/_layout.tsx.hbs +4 -2
- package/templates/frontend/native/unistyles/app/_layout.tsx.hbs +4 -2
- package/templates/frontend/native/uniwind/app/_layout.tsx.hbs +4 -3
- package/templates/frontend/nuxt/nuxt.config.ts.hbs +6 -3
- package/templates/frontend/react/next/next.config.ts.hbs +9 -8
- package/templates/frontend/react/next/src/components/providers.tsx.hbs +4 -1
- package/templates/frontend/react/next/tsconfig.json.hbs +2 -2
- package/templates/frontend/react/react-router/src/root.tsx.hbs +3 -4
- package/templates/frontend/react/tanstack-router/src/main.tsx.hbs +3 -2
- package/templates/frontend/react/tanstack-start/src/router.tsx.hbs +100 -108
- package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +25 -7
- package/templates/packages/config/tsconfig.base.json.hbs +1 -1
- package/templates/{deploy/alchemy → packages/env}/env.d.ts.hbs +6 -4
- package/templates/packages/env/package.json.hbs +7 -0
- package/templates/packages/env/src/native.ts.hbs +21 -0
- package/templates/packages/env/src/server.ts.hbs +38 -0
- package/templates/packages/env/src/web.ts.hbs +89 -0
- package/templates/packages/env/tsconfig.json.hbs +3 -0
- package/templates/{deploy/alchemy → packages/infra}/alchemy.run.ts.hbs +86 -82
- package/templates/packages/infra/package.json.hbs +10 -0
- 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.
|
|
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.
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
15
|
-
url: `${
|
|
16
|
-
|
|
17
|
-
url: `${
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
});
|
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
handler,
|
|
7
|
+
preloadAuthQuery,
|
|
8
|
+
isAuthenticated,
|
|
9
|
+
getToken,
|
|
10
|
+
fetchAuthQuery,
|
|
11
|
+
fetchAuthMutation,
|
|
12
|
+
fetchAuthAction,
|
|
11
13
|
} = convexBetterAuthNextJs({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
convexUrl: env.NEXT_PUBLIC_CONVEX_URL,
|
|
15
|
+
convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
|
|
14
16
|
});
|
package/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createAuthClient } from "better-auth/react";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
9
|
-
|
|
9
|
+
baseURL: env.VITE_CONVEX_SITE_URL,
|
|
10
|
+
plugins: [convexClient(), crossDomainClient()],
|
|
10
11
|
});
|
package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
handler,
|
|
6
|
+
getToken,
|
|
7
|
+
fetchAuthQuery,
|
|
8
|
+
fetchAuthMutation,
|
|
9
|
+
fetchAuthAction,
|
|
9
10
|
} = convexBetterAuthReactStart({
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
convexUrl: env.VITE_CONVEX_URL,
|
|
12
|
+
convexSiteUrl: env.VITE_CONVEX_SITE_URL,
|
|
12
13
|
});
|