kitcn 0.12.5 → 0.12.7

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.
@@ -1,31 +1,36 @@
1
1
  ## 8.B TanStack Start
2
2
 
3
- Explicit exception: current docs still use `@convex-dev/better-auth/*` helpers for TanStack Start integration.
4
-
3
+ CLI-first flow: scaffold the app, run `kitcn add auth --yes`, then treat the
4
+ files below as the generated reference output. They are not a separate manual
5
+ install path.
5
6
  ### 8.B.1 Auth client + auth server helpers
6
7
 
7
- **Create:** `src/lib/convex/auth/auth-client.ts`
8
+ **Create:** `src/lib/convex/auth-client.ts`
8
9
 
9
10
  ```ts
10
- import type { Auth } from "@convex/auth-shared";
11
- import { convexClient } from "@convex-dev/better-auth/client/plugins";
12
- import { adminClient, inferAdditionalFields } from "better-auth/client/plugins";
13
11
  import { createAuthClient } from "better-auth/react";
12
+ import { convexClient } from "kitcn/auth/client";
13
+ import { createAuthMutations } from "kitcn/react";
14
14
 
15
15
  export const authClient = createAuthClient({
16
16
  baseURL:
17
17
  typeof window === "undefined"
18
18
  ? (import.meta.env.VITE_SITE_URL as string | undefined)
19
19
  : window.location.origin,
20
- sessionOptions: { refetchOnWindowFocus: false },
21
- plugins: [inferAdditionalFields<Auth>(), adminClient(), convexClient()],
20
+ plugins: [convexClient()],
22
21
  });
22
+
23
+ export const {
24
+ useSignInMutationOptions,
25
+ useSignOutMutationOptions,
26
+ useSignUpMutationOptions,
27
+ } = createAuthMutations(authClient);
23
28
  ```
24
29
 
25
- **Create:** `src/lib/convex/auth/auth-server.ts`
30
+ **Create:** `src/lib/convex/auth-server.ts`
26
31
 
27
32
  ```ts
28
- import { convexBetterAuthReactStart } from "@convex-dev/better-auth/react-start";
33
+ import { convexBetterAuthReactStart } from "kitcn/auth/start";
29
34
 
30
35
  export const {
31
36
  handler,
@@ -34,8 +39,8 @@ export const {
34
39
  fetchAuthMutation,
35
40
  fetchAuthAction,
36
41
  } = convexBetterAuthReactStart({
37
- convexUrl: process.env.VITE_CONVEX_URL!,
38
- convexSiteUrl: process.env.VITE_CONVEX_SITE_URL!,
42
+ convexUrl: import.meta.env.VITE_CONVEX_URL!,
43
+ convexSiteUrl: import.meta.env.VITE_CONVEX_SITE_URL!,
39
44
  });
40
45
  ```
41
46
 
@@ -45,9 +50,9 @@ export const {
45
50
 
46
51
  ```ts
47
52
  import { createFileRoute } from "@tanstack/react-router";
48
- import { handler } from "@/lib/convex/auth/auth-server";
53
+ import { handler } from "@/lib/convex/auth-server";
49
54
 
50
- export const Route = createFileRoute("/api/auth/$")({
55
+ export const Route = createFileRoute("/api/auth/$" as never)({
51
56
  server: {
52
57
  handlers: {
53
58
  GET: ({ request }) => handler(request),
@@ -59,9 +64,47 @@ export const Route = createFileRoute("/api/auth/$")({
59
64
 
60
65
  ### 8.B.3 Caller/context and providers
61
66
 
62
- Use docs pattern from `tanstack-start.mdx` for:
67
+ **Create:** `src/lib/convex/server.ts`
68
+
69
+ ```ts
70
+ import { api } from "@convex/api";
71
+ import { getRequestHeaders } from "@tanstack/react-start/server";
72
+ import { createCallerFactory } from "kitcn/server";
73
+
74
+ import { getToken } from "@/lib/convex/auth-server";
75
+
76
+ const { createContext, createCaller } = createCallerFactory({
77
+ api,
78
+ convexSiteUrl: import.meta.env.VITE_CONVEX_SITE_URL!,
79
+ auth: {
80
+ getToken: async () => {
81
+ return {
82
+ token: await getToken(),
83
+ };
84
+ },
85
+ },
86
+ });
87
+
88
+ type ServerCaller = ReturnType<typeof createCaller>;
89
+
90
+ async function makeContext() {
91
+ const headers = await getRequestHeaders();
92
+ return createContext({ headers });
93
+ }
94
+
95
+ function createServerCaller(): ServerCaller {
96
+ return createCaller(async () => {
97
+ return await makeContext();
98
+ });
99
+ }
100
+
101
+ export function runServerCall<T>(fn: (caller: ServerCaller) => Promise<T> | T) {
102
+ const caller = createServerCaller();
103
+ return fn(caller);
104
+ }
105
+ ```
63
106
 
64
- - `createCallerFactory` + `runServerCall`
65
- - router context values (`convex`, `queryClient`, `convexQueryClient`)
66
- - provider wrapping with `ConvexAuthProvider` and `initialToken`
107
+ Use the docs pattern from `tanstack-start.mdx` for:
67
108
 
109
+ - `src/routes/__root.tsx` shell/provider wiring
110
+ - `src/lib/convex/convex-provider.tsx`