create-user-hub 0.4.3 → 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/.env.example +3 -2
- package/template/CLAUDE.md +6 -5
- package/template/README.md +6 -6
- package/template/package.json +3 -2
- 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/template/vite.config.ts +3 -3
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/.env.example
CHANGED
|
@@ -4,5 +4,6 @@ HUB_URL=https://hub.example.com
|
|
|
4
4
|
HUB_API_KEY=
|
|
5
5
|
|
|
6
6
|
# Written by bun run setup and the Convex CLI:
|
|
7
|
-
# CONVEX_DEPLOYMENT, VITE_CONVEX_URL, VITE_HUB_URL. The app's
|
|
8
|
-
#
|
|
7
|
+
# CONVEX_DEPLOYMENT, VITE_CONVEX_URL, VITE_HUB_URL. The app's hub, event and
|
|
8
|
+
# name go to user-hub.json, which is committed; its URLs live in the hub
|
|
9
|
+
# (bunx user-hub dev, bunx user-hub prod).
|
package/template/CLAUDE.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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
|
|
|
7
7
|
- `convex/hub.ts`: this app's key in the hub (`APP_KEY`, made from its event's slug and its name), written by `bun run setup`.
|
|
8
|
-
- The app belongs to one hub **event** (a workshop): its slug is `event` in `user-hub.json` (with the app's name
|
|
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`.
|
|
@@ -27,6 +28,6 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
27
28
|
|
|
28
29
|
## Commands
|
|
29
30
|
|
|
30
|
-
`bun run setup` (`user-hub setup`; once; signs the folder in first when run in a terminal and it is not; in a terminal it asks which hub event the app is for, or creates one, and saves it in `user-hub.json`), `bun run setup --event <slug>` (the event without asking: an agent asks the human which event and passes it, `bunx user-hub events list` lists them; never create an event unless the human asks, and then ask for its time zone too; with another event or `--name` than the ones in `user-hub.json`, the app is registered anew with a new app key and the earlier registration is left as it was), `
|
|
31
|
+
`bun run setup` (`user-hub setup`; once; signs the folder in first when run in a terminal and it is not; in a terminal it asks which hub event the app is for, or creates one, and saves it in `user-hub.json`), `bun run setup --event <slug>` (the event without asking: an agent asks the human which event and passes it, `bunx user-hub events list` lists them; never create an event unless the human asks, and then ask for its time zone too; with another event or `--name` than the ones in `user-hub.json`, the app is registered anew with a new app key and the earlier registration is left as it was), `bunx user-hub prod set <url>` (once deployed: registers the production URL so badge scans can reach the app and sets `HUB_ISSUER`/`HUB_JWKS` on the production Convex deployment; see the skill's "Production URL"; `bunx user-hub prod` shows it, `prod remove` removes it), `bunx user-hub dev list` / `dev add <url>` / `dev remove <url>` (the app has a list of development URLs, where the hub opens it for developers; the first is `http://localhost:` plus the port in the `dev` script; when changing the port, change the `dev` script too and add the new URL: the port is defined only there, and `server.strictPort` in `vite.config.ts` makes the dev server stop when the port is taken rather than move to another one the hub does not know), `bun run setup --unlisted` / `--listed` (keep the app out of the hub's badge app list, or put it back; new apps are listed), `bun run dev`, `bun run check` (`vp check`: format, lint and type-check), `bun run fix` (`vp check --fix`), `bun run typecheck`, `bun run build`, `just build` / `just push` (deploy Convex to production and build the Docker image against it; `IMAGE` sets the registry path; the container needs no env). Lint and format rules live in `vite.config.ts` (Vite+); `vp` is project-local, so run it through the scripts or `bunx vp`.
|
|
31
32
|
|
|
32
33
|
**Hub moved:** sign the folder in to the new hub (`bunx user-hub login --hub <new url>`, replacing `HUB_URL` and `HUB_API_KEY`), run `bun run setup --hub-moved` (with `--event <slug>` when the new hub has no event with this app's saved event; it updates this app's registration and sets `HUB_ISSUER`/`HUB_JWKS` on Convex, production included once a production URL is known, and `VITE_HUB_URL`), then `just push`, because `VITE_HUB_URL` is built into the frontend.
|
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
|
|
|
@@ -12,9 +12,9 @@ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and
|
|
|
12
12
|
|
|
13
13
|
Paste an API key from the hub's account page, or press Enter and approve the sign-in in your browser. It saves `HUB_URL` and `HUB_API_KEY` to `.env.local`. Skip this if you signed in when the app was created; `bun run setup` also asks when this folder is not signed in.
|
|
14
14
|
|
|
15
|
-
2. `bun run setup` (`user-hub setup`): creates your Convex project, registers the app with the hub and sets everything up. The hub runs many workshops, called events, and the app belongs to one: setup lists the active events and asks which (or creates a new one, asking for its name and time zone). Without a terminal, pass it: `bun run setup --event <slug>` (`bunx user-hub events list` lists the slugs). If another app already has this name in the event, it asks you for a new one (or run `bun run setup --name <name>`). New apps show in the hub's badge app list once they have a production URL; `bun run setup --unlisted` keeps this one out and `--listed` puts it back. Safe to run again. Setup saves the app's event
|
|
16
|
-
3. `bun run dev`, then open http://localhost:3000. You are sent to the hub to pick who to be, then back signed in. If something else already uses that port, the dev server stops with an error instead of moving to another port, because the hub only sends you back to
|
|
17
|
-
4. Once the app is deployed: `
|
|
15
|
+
2. `bun run setup` (`user-hub setup`): creates your Convex project, registers the app with the hub and sets everything up. The hub runs many workshops, called events, and the app belongs to one: setup lists the active events and asks which (or creates a new one, asking for its name and time zone). Without a terminal, pass it: `bun run setup --event <slug>` (`bunx user-hub events list` lists the slugs). If another app already has this name in the event, it asks you for a new one (or run `bun run setup --name <name>`). New apps show in the hub's badge app list once they have a production URL; `bun run setup --unlisted` keeps this one out and `--listed` puts it back. Safe to run again. Setup saves the app's event and name to `user-hub.json`: commit it. The app's URLs live in the hub: a list of development URLs (`bunx user-hub dev list`, `dev add <url>`, `dev remove <url>`) and a production URL (`bunx user-hub prod`, `prod set <url>`, `prod remove`). `--name` or `--event` with another name or event than the saved ones registers the app anew, with a new app key; setup leaves the earlier registration as it was.
|
|
16
|
+
3. `bun run dev`, then open http://localhost:3000. You are sent to the hub to pick who to be, then back signed in. If something else already uses that port, the dev server stops with an error instead of moving to another port, because the hub only sends you back to a registered URL. To use another port, change it in `package.json`'s `dev` script and add it to the app's development URLs: `bunx user-hub dev add http://localhost:<port>`.
|
|
17
|
+
4. Once the app is deployed: `bunx user-hub prod set https://your-app.example.com`, so badge scans can reach it. It also sets `HUB_ISSUER` and `HUB_JWKS` on the production Convex deployment.
|
|
18
18
|
|
|
19
19
|
## Deploy
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ The app ships as a Docker image served by Bun (`Dockerfile`, `server.ts`); it ne
|
|
|
23
23
|
- `just build`: deploys the Convex functions to production, then builds the image against that deployment and loads it into Docker. Try it with `docker run -p 3000:3000 __APP_KEY__`.
|
|
24
24
|
- `just push`: the same, built for servers (amd64) and pushed. Set your registry path first: `IMAGE=registry.example.com/team/__APP_KEY__ just push`, or edit `image` at the top of the `justfile`.
|
|
25
25
|
|
|
26
|
-
Then serve the container (port 3000) at your production URL and make sure the hub knows that URL (`
|
|
26
|
+
Then serve the container (port 3000) at your production URL and make sure the hub knows that URL (`bunx user-hub prod set <url>`). Badge scans reach the app once it is scheduled or forced live in the hub, or straight away while badges go to the hub's app list, if the app is listed (new apps are).
|
|
27
27
|
|
|
28
28
|
### Hub moved
|
|
29
29
|
|
|
@@ -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",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"@vitejs/plugin-react": "^6.3.0",
|
|
38
39
|
"oxc-transform-react": "^0.158.0",
|
|
39
40
|
"typescript": "^7.0.2",
|
|
40
|
-
"user-hub": "^0.
|
|
41
|
+
"user-hub": "^0.2.0",
|
|
41
42
|
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000",
|
|
42
43
|
"vite-plus": "1.7.0"
|
|
43
44
|
},
|
|
@@ -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">
|
package/template/vite.config.ts
CHANGED
|
@@ -19,9 +19,9 @@ const ignorePatterns = [
|
|
|
19
19
|
export default defineConfig({
|
|
20
20
|
resolve: { tsconfigPaths: true },
|
|
21
21
|
// The port lives in package.json's dev script, where `bun run setup` reads
|
|
22
|
-
// it to register the development URL. The hub only sends people back
|
|
23
|
-
//
|
|
24
|
-
// to the next free one.
|
|
22
|
+
// it to register the first development URL. The hub only sends people back
|
|
23
|
+
// to registered URLs, so stop with an error when the port is taken instead
|
|
24
|
+
// of moving to the next free one.
|
|
25
25
|
server: { strictPort: true },
|
|
26
26
|
// One convex/react in the browser: the hub provider gives the Convex
|
|
27
27
|
// client to the same context the app's Convex hooks read. Pre-bundled
|