kitcn 0.12.5 → 0.12.6

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