create-user-hub 0.4.4 → 0.4.5
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/README.md +2 -2
- package/package.json +1 -1
- package/template/CLAUDE.md +4 -3
- package/template/README.md +2 -2
- package/template/package.json +2 -1
- package/template/src/components/access-code-sign-in.tsx +122 -0
- package/template/src/components/ui/input-otp.tsx +84 -0
- package/template/src/routes/__root.tsx +2 -22
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **Private beta.** This starter needs a User Hub, which is not public yet. Until then it is only useful to teams already running one.
|
|
4
4
|
|
|
5
|
-
Start a new app with User Hub sign-in already wired: people scan their badge and arrive signed in.
|
|
5
|
+
Start a new app with User Hub sign-in already wired: people scan their badge and arrive signed in, or type the access code printed on it when they use the app on a computer.
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
bun create user-hub@latest my-app
|
|
@@ -14,7 +14,7 @@ Scripts and coding agents are never asked: pass `--hub-url` (or set `HUB_URL`),
|
|
|
14
14
|
|
|
15
15
|
You get a TanStack Start + Convex app with Tailwind, shadcn (dark theme) and Vite+ (Oxfmt, Oxlint), plus:
|
|
16
16
|
|
|
17
|
-
- **Sign-in** from [`@user-hub/auth`](https://www.npmjs.com/package/@user-hub/auth): a signed-in home page, a facilitator-only page, sign-out, and notes saved per person.
|
|
17
|
+
- **Sign-in** from [`@user-hub/auth`](https://www.npmjs.com/package/@user-hub/auth): an access-code screen for people signed out, a signed-in home page, a facilitator-only page, sign-out, and notes saved per person.
|
|
18
18
|
- **For coding agents:** `CLAUDE.md` (also as `AGENTS.md`) and the `user-hub-auth` (sign-in) and `user-hub-cli` (the hub from the terminal) skills in `.claude/skills`.
|
|
19
19
|
- **`bun run setup`:** one command (`user-hub setup`, from the [`user-hub`](https://www.npmjs.com/package/user-hub) CLI) that creates your Convex project, registers the app with your hub in an event (a workshop: it asks which, or creates one) and sets the values it needs. The same CLI runs the event's people and apps from the terminal (`bunx user-hub --help`).
|
|
20
20
|
|
package/package.json
CHANGED
package/template/CLAUDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# __APP_NAME__
|
|
2
2
|
|
|
3
|
-
A TanStack Start + Convex app whose sign-in comes from User Hub: people scan their badge and land here signed in. All auth comes from `@user-hub/auth`. In `.claude/skills`, follow the `user-hub-auth` skill for sign-in, roles and wiring, and the `user-hub-cli` skill for any `user-hub` command (signing in, setup, the event's people and apps).
|
|
3
|
+
A TanStack Start + Convex app whose sign-in comes from User Hub: people scan their badge and land here signed in, or type the access code printed on it. All auth comes from `@user-hub/auth`. In `.claude/skills`, follow the `user-hub-auth` skill for sign-in, roles and wiring, and the `user-hub-cli` skill for any `user-hub` command (signing in, setup, the event's people and apps).
|
|
4
4
|
|
|
5
5
|
## How it is wired
|
|
6
6
|
|
|
@@ -8,6 +8,7 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
8
8
|
- The app belongs to one hub **event** (a workshop): its slug is `event` in `user-hub.json` (with the hub and the app's name; its URLs live in the hub), saved by `bun run setup`. Commit it; it holds nothing secret.
|
|
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
|
+
- Signed out: `src/components/access-code-sign-in.tsx` (`useHubCodeSignIn`), the `signedOut` screen of `HubSignedIn`. Restyle it freely; keep the hook (the skill's `references/access-codes.md`). On a dev server a signed-out person goes to the hub to pick who to be; pass `devRedirect={false}` to the provider to see the code screen.
|
|
11
12
|
- 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
13
|
- 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.
|
|
13
14
|
- Sign out: `useHubSignOut()`.
|
|
@@ -15,9 +16,9 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
15
16
|
## Rules
|
|
16
17
|
|
|
17
18
|
- **Bun only:** `bun` and `bunx`; never `npm`, `npx`, `pnpm` or `yarn`.
|
|
18
|
-
- **Never hand-roll auth:** no login screens, passwords, sessions or token handling. If something is missing, it belongs in `@user-hub/auth`.
|
|
19
|
+
- **Never hand-roll auth:** no login screens, passwords, sessions or token handling. The access-code screen is the only sign-in UI, and it signs in only through `useHubCodeSignIn`. If something is missing, it belongs in `@user-hub/auth`.
|
|
19
20
|
- **Secrets:** `HUB_API_KEY` lives only in `.env.local`, saved by `user-hub login`. Never ask for it (or a password) in chat, write it yourself, print it, copy it, commit it, or print `.env.local`. When the folder is not signed in (`bunx user-hub whoami` exits with code 4), ask the human to run `bunx user-hub login`, or run `bunx user-hub login --browser` and give them the link it prints (the skill's "Signing in").
|
|
20
|
-
- **The hub from the terminal:** `bunx user-hub` (a devDependency) also lists and changes this event's people and apps (`user-hub people …`, `user-hub apps …`, `--help`). Run those only when the human asks; badge links it prints are lasting sign-
|
|
21
|
+
- **The hub from the terminal:** `bunx user-hub` (a devDependency) also lists and changes this event's people and apps (`user-hub people …`, `user-hub apps …`, `--help`). Run those only when the human asks; badge links and access codes it prints are lasting sign-ins, so never put them in code, commits or logs.
|
|
21
22
|
- **Convex:** public functions are thin wrappers (validators, an auth check, one call into `convex/model/`); every function has `args` and `returns` validators; reads use indexes and are bounded.
|
|
22
23
|
- **Convex AI files** are off (`"aiFiles": { "enabled": false }` in `convex.json`), so `convex dev` never asks to add them: they would append a block telling agents to use `npx` to this file and add its own skills. To add them anyway, run `bunx convex ai-files enable`.
|
|
23
24
|
- **UI:** shadcn components only (`bunx --bun shadcn@latest add …`), dark theme, works on mobile. Lists are `Item`s in an `ItemGroup` with actions in a `ButtonGroup`, never tables; forms use `Field`.
|
package/template/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# __APP_NAME__
|
|
2
2
|
|
|
3
|
-
A TanStack Start + Convex app with User Hub sign-in: people scan their badge and arrive signed in.
|
|
3
|
+
A TanStack Start + Convex app with User Hub sign-in: people scan their badge and arrive signed in, or type the access code printed on it.
|
|
4
4
|
|
|
5
5
|
## Get started
|
|
6
6
|
|
|
@@ -31,7 +31,7 @@ Sign this folder in to the new hub (`bunx user-hub login --hub <new url>`, which
|
|
|
31
31
|
|
|
32
32
|
## What's inside
|
|
33
33
|
|
|
34
|
-
- `src/routes/__root.tsx`: the hub providers inside `<body>`; `HubSignedIn` shows pages only to signed-in people. The server reads the person's token from a cookie, so pages render signed in from the first paint.
|
|
34
|
+
- `src/routes/__root.tsx`: the hub providers inside `<body>`; `HubSignedIn` shows pages only to signed-in people, and the access-code screen (`src/components/access-code-sign-in.tsx`) to everyone else. The server reads the person's token from a cookie, so pages render signed in from the first paint.
|
|
35
35
|
- `src/routes/index.tsx`: your name, team and role, what the server sees, sign-out, and notes saved per person.
|
|
36
36
|
- `src/routes/facilitator.tsx`: a facilitator-only page.
|
|
37
37
|
- `convex/`: notes keyed on the person's hub id. Public functions check who is asking (`requireHubUser`, `requireFacilitator`) and call `convex/model/`.
|
package/template/package.json
CHANGED
|
@@ -19,10 +19,11 @@
|
|
|
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.8.0",
|
|
23
23
|
"class-variance-authority": "^0.7.1",
|
|
24
24
|
"cn": "^0.5.2",
|
|
25
25
|
"convex": "^1.51.0",
|
|
26
|
+
"input-otp": "^1.5.0",
|
|
26
27
|
"lucide-react": "^1.76.0",
|
|
27
28
|
"react": "^19.3.1",
|
|
28
29
|
"react-dom": "^19.3.1",
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HUB_ACCESS_CODE_LENGTH,
|
|
3
|
+
type HubCodeError,
|
|
4
|
+
useHubCodeSignIn,
|
|
5
|
+
} from "@user-hub/auth/convex-react";
|
|
6
|
+
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
|
|
9
|
+
import { Button } from "@/components/ui/button";
|
|
10
|
+
import {
|
|
11
|
+
Field,
|
|
12
|
+
FieldDescription,
|
|
13
|
+
FieldError,
|
|
14
|
+
FieldLabel,
|
|
15
|
+
} from "@/components/ui/field";
|
|
16
|
+
import {
|
|
17
|
+
InputOTP,
|
|
18
|
+
InputOTPGroup,
|
|
19
|
+
InputOTPSlot,
|
|
20
|
+
} from "@/components/ui/input-otp";
|
|
21
|
+
|
|
22
|
+
function errorMessage(error: HubCodeError) {
|
|
23
|
+
switch (error.reason) {
|
|
24
|
+
case "invalid":
|
|
25
|
+
return "That code is not right. Check your badge and try again.";
|
|
26
|
+
case "ended":
|
|
27
|
+
return `${error.eventName || "This event"} has ended.`;
|
|
28
|
+
case "rateLimited": {
|
|
29
|
+
const minutes = Math.ceil(error.retryAfter / 60_000);
|
|
30
|
+
return `Too many wrong codes. Try again in ${minutes <= 1 ? "a minute" : `${minutes} minutes`}.`;
|
|
31
|
+
}
|
|
32
|
+
case "forbidden":
|
|
33
|
+
return "This app cannot sign people in from this address yet.";
|
|
34
|
+
case "unavailable":
|
|
35
|
+
return "Could not reach the hub. Try again.";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// What a person pasted, without spaces or dashes of any kind (a code copied
|
|
40
|
+
// from a document may hold an en dash).
|
|
41
|
+
const pastedCode = (text: string) => text.replace(/[\s\p{Pd}]/gu, "");
|
|
42
|
+
|
|
43
|
+
// The signed-out screen: people type the access code printed on their badge.
|
|
44
|
+
// A badge scan still lands here signed in.
|
|
45
|
+
export function AccessCodeSignIn() {
|
|
46
|
+
const { signIn, pending, error, reset } = useHubCodeSignIn();
|
|
47
|
+
const [code, setCode] = useState("");
|
|
48
|
+
const invalid = error ? true : undefined;
|
|
49
|
+
|
|
50
|
+
function submit(value: string) {
|
|
51
|
+
if (value.length === HUB_ACCESS_CODE_LENGTH) void signIn(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<main className="flex min-h-svh items-center justify-center p-4">
|
|
56
|
+
<form
|
|
57
|
+
className="flex w-full max-w-sm flex-col gap-6"
|
|
58
|
+
onSubmit={(event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
submit(code);
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<div className="flex flex-col gap-1">
|
|
64
|
+
<h1 className="text-2xl font-medium">Enter your access code</h1>
|
|
65
|
+
<p className="text-sm text-muted-foreground">
|
|
66
|
+
It is printed on your badge, under the QR code.
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
<Field data-invalid={invalid}>
|
|
70
|
+
<FieldLabel htmlFor="access-code" className="sr-only">
|
|
71
|
+
Access code
|
|
72
|
+
</FieldLabel>
|
|
73
|
+
<InputOTP
|
|
74
|
+
id="access-code"
|
|
75
|
+
maxLength={HUB_ACCESS_CODE_LENGTH}
|
|
76
|
+
pattern={REGEXP_ONLY_DIGITS_AND_CHARS}
|
|
77
|
+
// Codes are mostly letters: never the numeric keypad on phones.
|
|
78
|
+
inputMode="text"
|
|
79
|
+
autoCapitalize="characters"
|
|
80
|
+
autoCorrect="off"
|
|
81
|
+
value={code}
|
|
82
|
+
onChange={(value) => {
|
|
83
|
+
setCode(value.toUpperCase());
|
|
84
|
+
reset();
|
|
85
|
+
}}
|
|
86
|
+
onComplete={(value: string) => submit(value)}
|
|
87
|
+
pasteTransformer={pastedCode}
|
|
88
|
+
// Read-only rather than disabled while checking, so the field
|
|
89
|
+
// keeps focus and a wrong code can be fixed straight away.
|
|
90
|
+
readOnly={pending}
|
|
91
|
+
aria-invalid={invalid}
|
|
92
|
+
aria-describedby="access-code-message"
|
|
93
|
+
containerClassName="w-fit! gap-2"
|
|
94
|
+
>
|
|
95
|
+
<InputOTPGroup>
|
|
96
|
+
<InputOTPSlot index={0} aria-invalid={invalid} />
|
|
97
|
+
<InputOTPSlot index={1} aria-invalid={invalid} />
|
|
98
|
+
<InputOTPSlot index={2} aria-invalid={invalid} />
|
|
99
|
+
<InputOTPSlot index={3} aria-invalid={invalid} />
|
|
100
|
+
<InputOTPSlot index={4} aria-invalid={invalid} />
|
|
101
|
+
</InputOTPGroup>
|
|
102
|
+
</InputOTP>
|
|
103
|
+
{error ? (
|
|
104
|
+
<FieldError id="access-code-message">
|
|
105
|
+
{errorMessage(error)}
|
|
106
|
+
</FieldError>
|
|
107
|
+
) : (
|
|
108
|
+
<FieldDescription id="access-code-message">
|
|
109
|
+
Letters and numbers, 5 in all.
|
|
110
|
+
</FieldDescription>
|
|
111
|
+
)}
|
|
112
|
+
</Field>
|
|
113
|
+
<Button
|
|
114
|
+
type="submit"
|
|
115
|
+
disabled={pending || code.length < HUB_ACCESS_CODE_LENGTH}
|
|
116
|
+
>
|
|
117
|
+
{pending ? "Signing in…" : "Sign in"}
|
|
118
|
+
</Button>
|
|
119
|
+
</form>
|
|
120
|
+
</main>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cn } from "cn"
|
|
3
|
+
import { OTPInput, OTPInputContext } from "input-otp"
|
|
4
|
+
import { MinusIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
function InputOTP({
|
|
7
|
+
className,
|
|
8
|
+
containerClassName,
|
|
9
|
+
...props
|
|
10
|
+
}: React.ComponentProps<typeof OTPInput> & {
|
|
11
|
+
containerClassName?: string
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<OTPInput
|
|
15
|
+
data-slot="input-otp"
|
|
16
|
+
containerClassName={cn(
|
|
17
|
+
"cn-input-otp flex items-center has-disabled:opacity-50",
|
|
18
|
+
containerClassName
|
|
19
|
+
)}
|
|
20
|
+
spellCheck={false}
|
|
21
|
+
className={cn("disabled:cursor-not-allowed", className)}
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
data-slot="input-otp-group"
|
|
31
|
+
className={cn(
|
|
32
|
+
"flex items-center rounded-3xl has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40",
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function InputOTPSlot({
|
|
41
|
+
index,
|
|
42
|
+
className,
|
|
43
|
+
...props
|
|
44
|
+
}: React.ComponentProps<"div"> & {
|
|
45
|
+
index: number
|
|
46
|
+
}) {
|
|
47
|
+
const inputOTPContext = React.useContext(OTPInputContext)
|
|
48
|
+
const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
data-slot="input-otp-slot"
|
|
53
|
+
data-active={isActive}
|
|
54
|
+
className={cn(
|
|
55
|
+
"relative flex size-9 items-center justify-center border-y border-r border-input bg-input/50 text-sm transition-all outline-none first:rounded-l-3xl first:border-l last:rounded-r-3xl aria-invalid:border-destructive data-[active=true]:z-10 data-[active=true]:border-ring data-[active=true]:ring-3 data-[active=true]:ring-ring/30 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40",
|
|
56
|
+
className
|
|
57
|
+
)}
|
|
58
|
+
{...props}
|
|
59
|
+
>
|
|
60
|
+
{char}
|
|
61
|
+
{hasFakeCaret && (
|
|
62
|
+
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
|
63
|
+
<div className="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
data-slot="input-otp-separator"
|
|
74
|
+
className="flex items-center [&_svg:not([class*='size-'])]:size-4"
|
|
75
|
+
role="separator"
|
|
76
|
+
{...props}
|
|
77
|
+
>
|
|
78
|
+
<MinusIcon
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }
|
|
@@ -7,12 +7,7 @@ import {
|
|
|
7
7
|
import { getHubToken } from "@user-hub/auth/start";
|
|
8
8
|
import { ConvexReactClient } from "convex/react";
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
Empty,
|
|
12
|
-
EmptyDescription,
|
|
13
|
-
EmptyHeader,
|
|
14
|
-
EmptyTitle,
|
|
15
|
-
} from "@/components/ui/empty";
|
|
10
|
+
import { AccessCodeSignIn } from "@/components/access-code-sign-in";
|
|
16
11
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
17
12
|
|
|
18
13
|
import { APP_KEY } from "../../convex/hub";
|
|
@@ -70,7 +65,7 @@ function RootDocument({ children }: { children: React.ReactNode }) {
|
|
|
70
65
|
hubUrl={import.meta.env.VITE_HUB_URL}
|
|
71
66
|
initialToken={hubToken}
|
|
72
67
|
>
|
|
73
|
-
<HubSignedIn signedOut={<
|
|
68
|
+
<HubSignedIn signedOut={<AccessCodeSignIn />} loading={<Loading />}>
|
|
74
69
|
{children}
|
|
75
70
|
</HubSignedIn>
|
|
76
71
|
</ConvexHubAuthProvider>
|
|
@@ -80,21 +75,6 @@ function RootDocument({ children }: { children: React.ReactNode }) {
|
|
|
80
75
|
);
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
function SignedOut() {
|
|
84
|
-
return (
|
|
85
|
-
<main className="flex min-h-svh items-center justify-center p-4">
|
|
86
|
-
<Empty>
|
|
87
|
-
<EmptyHeader>
|
|
88
|
-
<EmptyTitle>Scan your badge to sign in</EmptyTitle>
|
|
89
|
-
<EmptyDescription>
|
|
90
|
-
Your badge's QR code brings you here, signed in.
|
|
91
|
-
</EmptyDescription>
|
|
92
|
-
</EmptyHeader>
|
|
93
|
-
</Empty>
|
|
94
|
-
</main>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
78
|
function Loading() {
|
|
99
79
|
return (
|
|
100
80
|
<main className="mx-auto flex max-w-2xl flex-col gap-4 p-4">
|