create-user-hub 0.4.1 → 0.4.3
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/package.json
CHANGED
package/template/CLAUDE.md
CHANGED
|
@@ -9,6 +9,7 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
9
9
|
- `convex/auth.config.ts`: `hubAuth({ app: APP_KEY })`; Convex trusts hub tokens through `HUB_ISSUER` and `HUB_JWKS` on the deployment.
|
|
10
10
|
- `src/routes/__root.tsx`: `ConvexHubAuthProvider` and `HubSignedIn` inside `<body>`. Never move them outside `<html>` or into the router's `Wrap`. Its `beforeLoad` reads the person's token on the server (`getHubToken`) and passes it as `initialToken`, so pages render signed in from the server: keep page components safe to render there (no `window` or `document` outside effects).
|
|
11
11
|
- People: `useHubUser()` in components; `requireHubUser(ctx)` / `requireFacilitator(ctx)` in Convex functions. Key data on the person's hub id; check roles on the server.
|
|
12
|
+
- Server functions and server routes that act as the person (calling another service, saving to Convex): `hubConvexMiddleware` from `@user-hub/auth/start-convex`, created once, with `hub.serverFn` on server functions and `hub.request` on server routes (the skill's `references/server-functions.md`). Never read the `Authorization` header, call `verifyHubToken` or build a `ConvexHttpClient` for the person yourself.
|
|
12
13
|
- Sign out: `useHubSignOut()`.
|
|
13
14
|
|
|
14
15
|
## Rules
|
package/template/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@tailwindcss/vite": "^4.3.5",
|
|
20
20
|
"@tanstack/react-router": "^1.170.46",
|
|
21
21
|
"@tanstack/react-start": "^1.169.7",
|
|
22
|
-
"@user-hub/auth": "^0.
|
|
22
|
+
"@user-hub/auth": "^0.7.0",
|
|
23
23
|
"class-variance-authority": "^0.7.1",
|
|
24
24
|
"cn": "^0.5.2",
|
|
25
25
|
"convex": "^1.51.0",
|
|
@@ -23,7 +23,14 @@ const CONVEX_URL = import.meta.env.VITE_CONVEX_URL;
|
|
|
23
23
|
if (!CONVEX_URL) {
|
|
24
24
|
throw new Error("Missing VITE_CONVEX_URL: run `bun run setup` first");
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
// expectAuth: queries wait for the person's token, so none runs signed out.
|
|
27
|
+
// initialAuthTokenReuse: Convex keeps that token until its refresh is due,
|
|
28
|
+
// instead of fetching another at once (a second sign-in that reruns every
|
|
29
|
+
// query).
|
|
30
|
+
const convex = new ConvexReactClient(CONVEX_URL, {
|
|
31
|
+
expectAuth: true,
|
|
32
|
+
initialAuthTokenReuse: true,
|
|
33
|
+
});
|
|
27
34
|
|
|
28
35
|
// The signed-in person's token from the request, so the server renders them
|
|
29
36
|
// instead of the loading state.
|
package/template/vite.config.ts
CHANGED
|
@@ -23,6 +23,11 @@ export default defineConfig({
|
|
|
23
23
|
// that URL, so stop with an error when the port is taken instead of moving
|
|
24
24
|
// to the next free one.
|
|
25
25
|
server: { strictPort: true },
|
|
26
|
+
// One convex/react in the browser: the hub provider gives the Convex
|
|
27
|
+
// client to the same context the app's Convex hooks read. Pre-bundled
|
|
28
|
+
// together, so a re-optimization can never split them into two copies
|
|
29
|
+
// ("Could not find Convex client").
|
|
30
|
+
optimizeDeps: { include: ["convex/react", "@user-hub/auth/convex-react"] },
|
|
26
31
|
plugins: lazyPlugins(() => [
|
|
27
32
|
tailwindcss(),
|
|
28
33
|
tanstackStart(),
|