create-user-hub 0.1.5 → 0.2.0
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 +3 -3
- package/index.js +102 -68
- package/package.json +1 -1
- package/template/.env.example +5 -3
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +23 -0
- package/template/CLAUDE.md +7 -2
- package/template/Dockerfile +6 -5
- package/template/README.md +12 -7
- package/template/convex/auth.config.ts +1 -0
- package/template/convex/me.ts +1 -0
- package/template/convex/model/notes.ts +1 -0
- package/template/convex/notes.ts +1 -0
- package/template/convex.json +3 -0
- package/template/package.json +25 -19
- package/template/scripts/setup.ts +177 -34
- package/template/src/router.tsx +1 -0
- package/template/src/routes/__root.tsx +4 -1
- package/template/src/routes/facilitator.tsx +2 -0
- package/template/src/routes/index.tsx +2 -0
- package/template/vite.config.ts +52 -7
- package/template/biome.json +0 -46
package/README.md
CHANGED
|
@@ -8,11 +8,11 @@ Start a new app with User Hub sign-in already wired: people scan their badge and
|
|
|
8
8
|
bun create user-hub@latest my-app
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
It asks for your hub's URL
|
|
11
|
+
It asks for your hub's URL (from your hub's admin) and checks the hub answers. Then it signs the new app in to the hub with your account: paste an API key from the hub's account page (it shows as stars), or press Enter and approve the sign-in in your browser. The app's `.env.local` gets `HUB_URL` and `HUB_API_KEY`.
|
|
12
12
|
|
|
13
|
-
Scripts and coding agents are never asked
|
|
13
|
+
Scripts and coding agents are never asked: pass `--hub-url` (or set `HUB_URL`), and set `HUB_API_KEY` in the environment if you have one (for example through your secret manager) to have it checked and saved. Without a key, sign in later from the app's folder (where `@user-hub/auth` is installed: `bunx hub-user` runs the installed CLI) with `bunx hub-user login` (a coding agent runs `bunx hub-user login --browser` and shows you the link to approve). Never run a bare `bunx hub-user` anywhere else: there it fetches an npm package called `hub-user`, which is not ours. The key is never a command-line flag, so it stays out of shell history.
|
|
14
14
|
|
|
15
|
-
You get a TanStack Start + Convex app with Tailwind, shadcn (dark theme) and
|
|
15
|
+
You get a TanStack Start + Convex app with Tailwind, shadcn (dark theme) and Vite+ (Oxfmt, Oxlint), plus:
|
|
16
16
|
|
|
17
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.
|
|
18
18
|
- **For coding agents:** `CLAUDE.md` (also as `AGENTS.md`) and the `user-hub-auth` skill in `.claude/skills`.
|
package/index.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// bun create user-hub@latest [my-app] [--hub-url <url>]
|
|
3
|
-
// Copies the starter, names it, saves the hub's URL
|
|
4
|
-
//
|
|
3
|
+
// Copies the starter, names it, saves the hub's URL to .env.local, installs
|
|
4
|
+
// it, adds the agent skill and signs the new app in to the hub.
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
6
|
+
// Signing in is `hub-user login` from @user-hub/auth, run inside the new app:
|
|
7
|
+
// it saves HUB_URL and HUB_API_KEY to .env.local. People in a terminal paste
|
|
8
|
+
// an API key or approve the sign-in in their browser. Scripts and agents set
|
|
9
|
+
// HUB_URL (or --hub-url) and, if they have one, HUB_API_KEY in the
|
|
10
|
+
// environment and are never asked. The key is never a command-line flag: that
|
|
11
|
+
// would leave it in shell history and process lists.
|
|
10
12
|
import { existsSync, readdirSync } from "node:fs";
|
|
11
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
cp,
|
|
15
|
+
mkdir,
|
|
16
|
+
readFile,
|
|
17
|
+
rename,
|
|
18
|
+
rm,
|
|
19
|
+
symlink,
|
|
20
|
+
writeFile,
|
|
21
|
+
} from "node:fs/promises";
|
|
12
22
|
import { basename, join, resolve } from "node:path";
|
|
13
23
|
import { parseArgs } from "node:util";
|
|
14
24
|
|
|
@@ -29,43 +39,6 @@ function slug(text) {
|
|
|
29
39
|
.replace(/^-+|-+$/g, "");
|
|
30
40
|
}
|
|
31
41
|
|
|
32
|
-
// Reads a line without echoing it, printing a star per character.
|
|
33
|
-
function secret(question) {
|
|
34
|
-
process.stdout.write(question);
|
|
35
|
-
process.stdin.setRawMode(true);
|
|
36
|
-
process.stdin.resume();
|
|
37
|
-
process.stdin.setEncoding("utf8");
|
|
38
|
-
return new Promise((done) => {
|
|
39
|
-
let value = "";
|
|
40
|
-
const finish = () => {
|
|
41
|
-
process.stdin.off("data", onData);
|
|
42
|
-
process.stdin.setRawMode(false);
|
|
43
|
-
process.stdin.pause();
|
|
44
|
-
process.stdout.write("\n");
|
|
45
|
-
done(value);
|
|
46
|
-
};
|
|
47
|
-
const onData = (chunk) => {
|
|
48
|
-
for (const char of chunk) {
|
|
49
|
-
if (char === "\r" || char === "\n") return finish();
|
|
50
|
-
if (char === "\u0003") {
|
|
51
|
-
process.stdout.write("\n");
|
|
52
|
-
process.exit(130);
|
|
53
|
-
}
|
|
54
|
-
if (char === "\u007f" || char === "\b") {
|
|
55
|
-
if (value) {
|
|
56
|
-
value = value.slice(0, -1);
|
|
57
|
-
process.stdout.write("\b \b");
|
|
58
|
-
}
|
|
59
|
-
} else if (char >= " ") {
|
|
60
|
-
value += char;
|
|
61
|
-
process.stdout.write("*");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
process.stdin.on("data", onData);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
42
|
// The hub answers its public key at this path; anything else is a typo or a
|
|
70
43
|
// hub that is down.
|
|
71
44
|
async function hubAnswers(url) {
|
|
@@ -98,16 +71,22 @@ const dest = resolve(target);
|
|
|
98
71
|
if (existsSync(dest) && readdirSync(dest).length > 0) {
|
|
99
72
|
fail(`${dest} already exists and is not empty.`);
|
|
100
73
|
}
|
|
74
|
+
// Whether this run makes the folder, or fills one that is there and empty.
|
|
75
|
+
const destCreated = !existsSync(dest);
|
|
101
76
|
|
|
102
77
|
let hubUrl = flags["hub-url"] ?? process.env.HUB_URL;
|
|
103
|
-
|
|
104
|
-
if (interactive &&
|
|
105
|
-
console.log("\nYour hub's URL
|
|
106
|
-
console.log("Press Enter to skip and
|
|
107
|
-
hubUrl
|
|
108
|
-
if (hubUrl) adminPassword ||= await secret("Admin password: ");
|
|
78
|
+
const apiKey = process.env.HUB_API_KEY?.trim();
|
|
79
|
+
if (interactive && !hubUrl) {
|
|
80
|
+
console.log("\nYour hub's URL (from your hub's admin).");
|
|
81
|
+
console.log("Press Enter to skip and sign in to the hub later.\n");
|
|
82
|
+
hubUrl = prompt("Hub URL:") ?? "";
|
|
109
83
|
}
|
|
110
84
|
hubUrl = hubUrl?.trim().replace(/\/+$/, "");
|
|
85
|
+
if (apiKey && !hubUrl) {
|
|
86
|
+
fail(
|
|
87
|
+
"HUB_API_KEY is set, but not the hub it belongs to: pass --hub-url or set HUB_URL.",
|
|
88
|
+
);
|
|
89
|
+
}
|
|
111
90
|
if (hubUrl && !/^https?:\/\//.test(hubUrl)) {
|
|
112
91
|
fail(`The hub URL must start with https:// (got "${hubUrl}").`);
|
|
113
92
|
}
|
|
@@ -122,6 +101,16 @@ await cp(TEMPLATE, dest, { recursive: true });
|
|
|
122
101
|
await rename(join(dest, "gitignore"), join(dest, ".gitignore"));
|
|
123
102
|
await rename(join(dest, "dockerignore"), join(dest, ".dockerignore"));
|
|
124
103
|
|
|
104
|
+
// Testing unreleased @user-hub/auth: CREATE_USER_HUB_AUTH_SPEC (for example
|
|
105
|
+
// file:/path/to/user-hub-auth) replaces its version range before installing.
|
|
106
|
+
const authSpec = process.env.CREATE_USER_HUB_AUTH_SPEC;
|
|
107
|
+
if (authSpec) {
|
|
108
|
+
const path = join(dest, "package.json");
|
|
109
|
+
const pkg = JSON.parse(await readFile(path, "utf8"));
|
|
110
|
+
pkg.dependencies["@user-hub/auth"] = authSpec;
|
|
111
|
+
await writeFile(path, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
112
|
+
}
|
|
113
|
+
|
|
125
114
|
for (const file of [
|
|
126
115
|
"package.json",
|
|
127
116
|
"README.md",
|
|
@@ -139,23 +128,42 @@ for (const file of [
|
|
|
139
128
|
}
|
|
140
129
|
await symlink("CLAUDE.md", join(dest, "AGENTS.md"));
|
|
141
130
|
|
|
142
|
-
// .env.local is gitignored
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
adminPassword && `HUB_ADMIN_PASSWORD=${adminPassword}`,
|
|
146
|
-
].filter(Boolean);
|
|
147
|
-
if (env.length > 0) {
|
|
148
|
-
await writeFile(join(dest, ".env.local"), `${env.join("\n")}\n`, {
|
|
131
|
+
// .env.local is gitignored. hub-user login adds HUB_API_KEY next to the URL.
|
|
132
|
+
if (hubUrl) {
|
|
133
|
+
await writeFile(join(dest, ".env.local"), `HUB_URL=${hubUrl}\n`, {
|
|
149
134
|
mode: 0o600,
|
|
150
135
|
});
|
|
151
136
|
}
|
|
152
137
|
|
|
153
|
-
const run = (command) =>
|
|
154
|
-
Bun.spawn(command, { cwd: dest, stdio: [
|
|
138
|
+
const run = (command, stdin = "inherit") =>
|
|
139
|
+
Bun.spawn(command, { cwd: dest, stdio: [stdin, "inherit", "inherit"] })
|
|
155
140
|
.exited;
|
|
156
141
|
|
|
142
|
+
// A half-made app would block running the same command again ("already
|
|
143
|
+
// exists"), so a failed or interrupted install takes back what this run
|
|
144
|
+
// wrote: the folder when this run made it, else only what it put inside.
|
|
157
145
|
console.log("\nInstalling dependencies");
|
|
158
|
-
|
|
146
|
+
let interrupted = false;
|
|
147
|
+
const onInterrupt = () => {
|
|
148
|
+
interrupted = true;
|
|
149
|
+
};
|
|
150
|
+
// Ctrl-C reaches bun install too; wait for it to stop before cleaning up.
|
|
151
|
+
process.on("SIGINT", onInterrupt);
|
|
152
|
+
const installed = (await run(["bun", "install"])) === 0;
|
|
153
|
+
process.off("SIGINT", onInterrupt);
|
|
154
|
+
if (!installed || interrupted) {
|
|
155
|
+
if (destCreated) {
|
|
156
|
+
await rm(dest, { recursive: true, force: true });
|
|
157
|
+
} else {
|
|
158
|
+
for (const entry of readdirSync(dest)) {
|
|
159
|
+
await rm(join(dest, entry), { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
console.error(
|
|
163
|
+
`\n✗ ${interrupted ? "Stopped while installing" : "bun install failed"}, so ${destCreated ? `${dest} was removed` : `what was copied into ${dest} was removed`}. Run the same command again.`,
|
|
164
|
+
);
|
|
165
|
+
process.exit(interrupted ? 130 : 1);
|
|
166
|
+
}
|
|
159
167
|
|
|
160
168
|
// The skill ships inside @user-hub/auth: one copy for every agent, linked
|
|
161
169
|
// for Claude Code.
|
|
@@ -169,22 +177,45 @@ await symlink("../.agents/skills", join(dest, ".claude/skills"));
|
|
|
169
177
|
|
|
170
178
|
await run(["git", "init", "-q"]);
|
|
171
179
|
|
|
172
|
-
|
|
180
|
+
// Sign the new app in: a key from the environment is checked with the hub and
|
|
181
|
+
// saved; in a terminal, hub-user asks for a key or a browser sign-in.
|
|
182
|
+
let signedIn = false;
|
|
183
|
+
if (hubUrl && (apiKey || interactive)) {
|
|
184
|
+
// --no-install: the CLI installed above, never an npm package of that name.
|
|
185
|
+
const login = [
|
|
186
|
+
"bun",
|
|
187
|
+
"x",
|
|
188
|
+
"--no-install",
|
|
189
|
+
"hub-user",
|
|
190
|
+
"login",
|
|
191
|
+
"--hub",
|
|
192
|
+
hubUrl,
|
|
193
|
+
];
|
|
194
|
+
console.log("\nSigning in to the hub");
|
|
195
|
+
// Ctrl-C belongs to hub-user; the app exists either way, so still say what
|
|
196
|
+
// is next.
|
|
197
|
+
const ignore = () => {};
|
|
198
|
+
process.on("SIGINT", ignore);
|
|
199
|
+
signedIn = apiKey
|
|
200
|
+
? (await run([...login, "--api-key-stdin"], new Blob([apiKey]))) === 0
|
|
201
|
+
: (await run(login)) === 0;
|
|
202
|
+
process.off("SIGINT", ignore);
|
|
203
|
+
}
|
|
204
|
+
|
|
173
205
|
console.log(`
|
|
174
|
-
✓ Created ${name}
|
|
206
|
+
✓ Created ${name}${hubUrl && !signedIn ? ", not signed in to the hub yet" : ""}
|
|
175
207
|
|
|
176
208
|
Next:
|
|
177
209
|
|
|
178
210
|
cd ${target}
|
|
179
211
|
${
|
|
180
|
-
|
|
212
|
+
signedIn
|
|
181
213
|
? ""
|
|
182
214
|
: `
|
|
183
|
-
0.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
HUB_ADMIN_PASSWORD=…
|
|
215
|
+
0. bunx hub-user login signs this app in to the hub${hubUrl ? "" : "\n (its URL comes from your hub's admin)"}
|
|
216
|
+
Paste an API key from the hub's account page, or press
|
|
217
|
+
Enter to approve the sign-in in your browser. A coding
|
|
218
|
+
agent runs it with --browser and shows you the link.
|
|
188
219
|
`
|
|
189
220
|
}
|
|
190
221
|
1. bun run setup connects Convex and the hub, once
|
|
@@ -193,3 +224,6 @@ ${
|
|
|
193
224
|
Using a coding agent? It reads CLAUDE.md (AGENTS.md) and the
|
|
194
225
|
user-hub-auth skill in .claude/skills.
|
|
195
226
|
`);
|
|
227
|
+
|
|
228
|
+
// A key passed in by a script that the hub refused is an error for it to see.
|
|
229
|
+
if (apiKey && !signedIn) process.exit(1);
|
package/package.json
CHANGED
package/template/.env.example
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Saved by bunx hub-user login (bun run setup runs it when they are missing).
|
|
2
|
+
# Never commit them; never share the API key.
|
|
2
3
|
HUB_URL=https://hub.example.com
|
|
3
|
-
|
|
4
|
+
HUB_API_KEY=
|
|
4
5
|
|
|
5
6
|
# Written by bun run setup and the Convex CLI:
|
|
6
7
|
# CONVEX_DEPLOYMENT, VITE_CONVEX_URL, VITE_HUB_URL, HUB_APP_NAME (this app's
|
|
7
|
-
# name in the hub, once registered),
|
|
8
|
+
# name in the hub, once registered), HUB_APP_DEV_URL (its development URL),
|
|
9
|
+
# HUB_APP_PROD_URL (once given)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files.watcherExclude": {
|
|
3
|
+
"**/routeTree.gen.ts": true
|
|
4
|
+
},
|
|
5
|
+
"search.exclude": {
|
|
6
|
+
"**/routeTree.gen.ts": true
|
|
7
|
+
},
|
|
8
|
+
"files.readonlyInclude": {
|
|
9
|
+
"**/routeTree.gen.ts": true
|
|
10
|
+
},
|
|
11
|
+
"editor.defaultFormatter": "oxc.oxc-vscode",
|
|
12
|
+
"[javascript]": { "editor.defaultFormatter": "oxc.oxc-vscode" },
|
|
13
|
+
"[javascriptreact]": { "editor.defaultFormatter": "oxc.oxc-vscode" },
|
|
14
|
+
"[typescript]": { "editor.defaultFormatter": "oxc.oxc-vscode" },
|
|
15
|
+
"[typescriptreact]": { "editor.defaultFormatter": "oxc.oxc-vscode" },
|
|
16
|
+
"oxc.disableNestedConfig": true,
|
|
17
|
+
"oxc.fmt.disableNestedConfig": true,
|
|
18
|
+
"editor.formatOnSave": true,
|
|
19
|
+
"editor.formatOnSaveMode": "file",
|
|
20
|
+
"editor.codeActionsOnSave": {
|
|
21
|
+
"source.fixAll.oxc": "explicit"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/template/CLAUDE.md
CHANGED
|
@@ -14,11 +14,16 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
14
14
|
|
|
15
15
|
- **Bun only:** `bun` and `bunx`; never `npm`, `npx`, `pnpm` or `yarn`.
|
|
16
16
|
- **Never hand-roll auth:** no login screens, passwords, sessions or token handling. If something is missing, it belongs in `@user-hub/auth`.
|
|
17
|
-
- **Secrets:** `
|
|
17
|
+
- **Secrets:** `HUB_API_KEY` lives only in `.env.local`, saved by `hub-user 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 hub-user whoami` exits with code 4), ask the human to run `bunx hub-user login`, or run `bunx hub-user login --browser` and give them the link it prints (the skill's "Signing in"). Run `bunx hub-user` only in this folder with the dependencies installed (`bun install`): it runs the CLI from `@user-hub/auth`; anywhere else it fetches an npm package called `hub-user`, which is not ours.
|
|
18
18
|
- **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.
|
|
19
|
+
- **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`.
|
|
19
20
|
- **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`.
|
|
20
21
|
- **Imports:** the `@/` alias for `src/`.
|
|
22
|
+
- **Generated files:** never edit `src/routeTree.gen.ts`, `convex/_generated/*` or `src/components/ui/*` by hand.
|
|
23
|
+
- **Lint:** never disable a lint rule: find the fix in the library's docs, or say so.
|
|
21
24
|
|
|
22
25
|
## Commands
|
|
23
26
|
|
|
24
|
-
`bun run setup` (once), `bun run setup --prod <url>` (once deployed: registers the production URL so badge scans can reach the app; see the skill's "Production URL"), `bun run dev`, `bun run check
|
|
27
|
+
`bun run setup` (once; signs the folder in first when run in a terminal and it is not), `bun run setup --prod <url>` (once deployed: registers the production URL so badge scans can reach the app; see the skill's "Production URL"), `bun run setup --dev <url>` (change where the hub opens the app for developers; first registered as `http://localhost:` plus the port in the `dev` script, kept on later runs; change the port in the `dev` script too), `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`.
|
|
28
|
+
|
|
29
|
+
**Hub moved:** sign the folder in to the new hub (`bunx hub-user login --hub <new url>`, replacing `HUB_URL` and `HUB_API_KEY`), run `bun run setup` (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/Dockerfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# syntax=docker/dockerfile:1
|
|
2
2
|
|
|
3
|
-
# TanStack Start built by Vite, served by Bun (server.ts). Build
|
|
4
|
-
# `just build` or `just push`, which also deploy Convex to production.
|
|
3
|
+
# TanStack Start built by Vite+ (`vp build`), served by Bun (server.ts). Build
|
|
4
|
+
# it with `just build` or `just push`, which also deploy Convex to production.
|
|
5
5
|
FROM oven/bun:1.4-slim AS base
|
|
6
6
|
WORKDIR /app
|
|
7
7
|
|
|
@@ -10,15 +10,16 @@ FROM base AS deps
|
|
|
10
10
|
COPY --link bun.lock package.json ./
|
|
11
11
|
RUN bun install --frozen-lockfile
|
|
12
12
|
|
|
13
|
-
# Build:
|
|
14
|
-
# values are public and inlined into the bundle, so they are build
|
|
13
|
+
# Build: vp build (Vite+) emits dist/client and dist/server/server.js. Both
|
|
14
|
+
# VITE_ values are public and inlined into the bundle, so they are build
|
|
15
|
+
# arguments.
|
|
15
16
|
FROM deps AS build
|
|
16
17
|
COPY . .
|
|
17
18
|
ARG VITE_CONVEX_URL
|
|
18
19
|
ARG VITE_HUB_URL
|
|
19
20
|
RUN test -n "$VITE_CONVEX_URL" -a -n "$VITE_HUB_URL" || (echo "Pass --build-arg VITE_CONVEX_URL=… and --build-arg VITE_HUB_URL=…, or run just build" && exit 1)
|
|
20
21
|
ENV NODE_ENV=production CI=1 VITE_CONVEX_URL=${VITE_CONVEX_URL} VITE_HUB_URL=${VITE_HUB_URL}
|
|
21
|
-
RUN rm -rf dist .tanstack node_modules/.vite && bunx --bun
|
|
22
|
+
RUN rm -rf dist .tanstack node_modules/.vite && bunx --bun vp build && bun run typecheck
|
|
22
23
|
|
|
23
24
|
# Production dependencies only.
|
|
24
25
|
FROM base AS prod-deps
|
package/template/README.md
CHANGED
|
@@ -4,15 +4,16 @@ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and
|
|
|
4
4
|
|
|
5
5
|
## Get started
|
|
6
6
|
|
|
7
|
-
1.
|
|
7
|
+
1. Sign this folder in to your hub (your hub's admin gives you its URL and an account):
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
|
|
11
|
-
HUB_ADMIN_PASSWORD=…
|
|
10
|
+
bunx hub-user login --hub https://hub.example.com
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
Run it in this folder with the dependencies installed (`bun install` first in a fresh clone): `bunx hub-user` runs the CLI that comes with `@user-hub/auth`. Anywhere else it fetches an npm package called `hub-user`, which is not ours. 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
|
+
|
|
15
|
+
2. `bun run setup`: creates your Convex project, registers the app with the hub and sets everything up. If another app already has this name in the hub, 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. If the hub later says your account may not change this app (it belongs to another account), ask a hub admin, or register it under a new name: delete `HUB_APP_NAME` from `.env.local` and run `bun run setup --name <new name>`.
|
|
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. To use another port, change it in `package.json`'s `dev` script and run `bun run setup --dev http://localhost:<port>`; later runs of setup keep the development URL.
|
|
16
17
|
4. Once the app is deployed: `bun run setup --prod https://your-app.example.com`, so badge scans can reach it. Setup asks for this the first time; press Enter to skip until you deploy.
|
|
17
18
|
|
|
18
19
|
## Deploy
|
|
@@ -22,7 +23,11 @@ The app ships as a Docker image served by Bun (`Dockerfile`, `server.ts`); it ne
|
|
|
22
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__`.
|
|
23
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`.
|
|
24
25
|
|
|
25
|
-
Then serve the container (port 3000) at your production URL
|
|
26
|
+
Then serve the container (port 3000) at your production URL and make sure the hub knows that URL (`bun run setup --prod <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
|
+
|
|
28
|
+
### Hub moved
|
|
29
|
+
|
|
30
|
+
Sign this folder in to the new hub (`bunx hub-user login --hub <new url>`, which replaces `HUB_URL` and `HUB_API_KEY` in `.env.local`) and run `bun run setup`: it updates this app's registration with the new hub and sets `HUB_ISSUER`, `HUB_JWKS` (on the production Convex deployment too, once it has a production URL) and `VITE_HUB_URL`. Then `just push`, because `VITE_HUB_URL` is built into the frontend.
|
|
26
31
|
|
|
27
32
|
## What's inside
|
|
28
33
|
|
|
@@ -33,6 +38,6 @@ Then serve the container (port 3000) at your production URL, make sure the hub k
|
|
|
33
38
|
|
|
34
39
|
## Commands
|
|
35
40
|
|
|
36
|
-
`bun run dev`, `bun run check` (
|
|
41
|
+
`bun run dev`, `bun run check` (Vite+: format, lint and type-check), `bun run fix` (the same, fixing what it can), `bun run typecheck`, `bun run build`, `bun run start` (production server), `just build`, `just push`.
|
|
37
42
|
|
|
38
43
|
Coding agents: see `CLAUDE.md` and the `user-hub-auth` skill in `.claude/skills`.
|
package/template/convex/me.ts
CHANGED
package/template/convex/notes.ts
CHANGED
package/template/convex.json
CHANGED
package/template/package.json
CHANGED
|
@@ -4,38 +4,44 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"setup": "bun scripts/setup.ts",
|
|
7
|
-
"dev": "convex dev --start \"
|
|
8
|
-
"build": "
|
|
7
|
+
"dev": "convex dev --start \"vp dev --port 3000\"",
|
|
8
|
+
"build": "vp build",
|
|
9
9
|
"start": "bun run server.ts",
|
|
10
|
-
"check": "
|
|
10
|
+
"check": "vp check",
|
|
11
|
+
"fix": "vp check --fix",
|
|
12
|
+
"lint": "vp lint",
|
|
13
|
+
"fmt": "vp fmt",
|
|
11
14
|
"typecheck": "tsc --noEmit -p . && tsc --noEmit -p convex"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
14
|
-
"@base-ui/react": "^1.
|
|
17
|
+
"@base-ui/react": "^1.9.0",
|
|
15
18
|
"@fontsource-variable/oxanium": "^5.3.0",
|
|
16
19
|
"@tailwindcss/vite": "^4.3.3",
|
|
17
|
-
"@tanstack/react-router": "^1.170.
|
|
18
|
-
"@tanstack/react-start": "^1.
|
|
19
|
-
"@user-hub/auth": "^0.
|
|
20
|
+
"@tanstack/react-router": "^1.170.46",
|
|
21
|
+
"@tanstack/react-start": "^1.169.4",
|
|
22
|
+
"@user-hub/auth": "^0.3.0",
|
|
20
23
|
"class-variance-authority": "^0.7.1",
|
|
21
|
-
"cn": "^0.
|
|
22
|
-
"convex": "^1.
|
|
23
|
-
"lucide-react": "^1.
|
|
24
|
-
"react": "^19.3.
|
|
25
|
-
"react-dom": "^19.3.
|
|
26
|
-
"shadcn": "^4.
|
|
24
|
+
"cn": "^0.5.0",
|
|
25
|
+
"convex": "^1.48.0",
|
|
26
|
+
"lucide-react": "^1.61.0",
|
|
27
|
+
"react": "^19.3.1",
|
|
28
|
+
"react-dom": "^19.3.1",
|
|
29
|
+
"shadcn": "^4.22.1",
|
|
27
30
|
"tailwindcss": "^4.3.3",
|
|
28
31
|
"tw-animate-css": "^1.4.0"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@rolldown/plugin-babel": "^0.2.4",
|
|
33
|
-
"@types/bun": "^1.4.2",
|
|
34
|
+
"@types/bun": "^1.4.4",
|
|
34
35
|
"@types/react": "^19.3.0",
|
|
35
36
|
"@types/react-dom": "^19.3.0",
|
|
36
|
-
"@vitejs/plugin-react": "^6.1.
|
|
37
|
-
"
|
|
37
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
38
|
+
"oxc-transform-react": "^0.155.0",
|
|
38
39
|
"typescript": "^7.0.2",
|
|
39
|
-
"vite": "
|
|
40
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
41
|
+
"vite-plus": "1.4.0"
|
|
42
|
+
},
|
|
43
|
+
"overrides": {
|
|
44
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
45
|
+
"vitest": "5.0.5"
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
// Setup: creates the Convex project, registers this app with User Hub and
|
|
2
2
|
// sets the values that make Convex trust the hub's tokens.
|
|
3
|
-
// Run: bun run setup [--name <name>] [--prod <url>]
|
|
4
|
-
// it with --prod once the app
|
|
5
|
-
//
|
|
3
|
+
// Run: bun run setup [--name <name>] [--prod <url>] [--dev <url>]
|
|
4
|
+
// [--listed|--unlisted]. Safe to run again; run it with --prod once the app
|
|
5
|
+
// is deployed so badge scans can reach it. --dev changes where the hub opens
|
|
6
|
+
// the app for developers (first registered as http://localhost:<the port in
|
|
7
|
+
// package.json's dev script>); later runs keep it. --unlisted keeps the app
|
|
8
|
+
// out of the hub's badge app list (new apps are listed), --listed puts it
|
|
9
|
+
// back; without either, the hub keeps the current setting.
|
|
10
|
+
// Needs HUB_URL and HUB_API_KEY in .env.local (Bun loads it), which
|
|
11
|
+
// `bunx hub-user login` saves; in a terminal, setup runs it when they are
|
|
12
|
+
// missing or the hub refuses the key.
|
|
6
13
|
|
|
7
14
|
import { existsSync, renameSync } from "node:fs";
|
|
8
15
|
import { rename } from "node:fs/promises";
|
|
9
16
|
|
|
10
17
|
const ENV_FILE = ".env.local";
|
|
11
18
|
const HUB_FILE = "convex/hub.ts";
|
|
12
|
-
const DEV_URL = "http://localhost:3000";
|
|
13
19
|
const AUTH_CONFIG = "convex/auth.config.ts";
|
|
14
20
|
const AUTH_CONFIG_ASIDE = "convex/auth.config.ts.setup";
|
|
15
21
|
|
|
@@ -28,16 +34,34 @@ function fail(message: string): never {
|
|
|
28
34
|
process.exit(1);
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
// capture keeps stdout; hub-user also keeps stderr, so its "run `bunx
|
|
38
|
+
// hub-user login`" hint can give way to setup's own message (setup runs the
|
|
39
|
+
// login itself) and other errors are printed as they are.
|
|
40
|
+
async function run(
|
|
41
|
+
command: string[],
|
|
42
|
+
{ capture = false, hubUser = false } = {},
|
|
43
|
+
) {
|
|
32
44
|
const child = Bun.spawn(command, {
|
|
33
45
|
stdin: "inherit",
|
|
34
46
|
stdout: capture ? "pipe" : "inherit",
|
|
35
|
-
stderr: "inherit",
|
|
47
|
+
stderr: hubUser ? "pipe" : "inherit",
|
|
36
48
|
env: process.env,
|
|
37
49
|
});
|
|
38
|
-
const output =
|
|
50
|
+
const [output, errors] = await Promise.all([
|
|
51
|
+
capture ? new Response(child.stdout).text() : "",
|
|
52
|
+
hubUser ? new Response(child.stderr).text() : "",
|
|
53
|
+
]);
|
|
39
54
|
const code = await child.exited;
|
|
40
|
-
return { ok: code === 0, code, output };
|
|
55
|
+
return { ok: code === 0, code, output, errors };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// hub-user from this app's node_modules; --no-install never fetches a package
|
|
59
|
+
// of that name from npm.
|
|
60
|
+
function hubUser(...args: string[]) {
|
|
61
|
+
return run(["bunx", "--no-install", "hub-user", ...args], {
|
|
62
|
+
capture: true,
|
|
63
|
+
hubUser: true,
|
|
64
|
+
});
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
async function readEnv() {
|
|
@@ -53,15 +77,81 @@ async function writeEnv(key: string, value: string) {
|
|
|
53
77
|
await Bun.write(ENV_FILE, `${[...lines, `${key}=${value}`].join("\n")}\n`);
|
|
54
78
|
}
|
|
55
79
|
|
|
80
|
+
// Signs this folder in to the hub with `hub-user login` (an API key or the
|
|
81
|
+
// browser), then picks up the HUB_URL and HUB_API_KEY it saved, which this
|
|
82
|
+
// process read from .env.local before they were there.
|
|
83
|
+
async function signIn() {
|
|
84
|
+
step("Signing this folder in to User Hub");
|
|
85
|
+
const hub = process.env.HUB_URL;
|
|
86
|
+
const login = await run([
|
|
87
|
+
"bunx",
|
|
88
|
+
"--no-install",
|
|
89
|
+
"hub-user",
|
|
90
|
+
"login",
|
|
91
|
+
...(hub ? ["--hub", hub] : []),
|
|
92
|
+
]);
|
|
93
|
+
if (!login.ok) fail("Not signed in to the hub. Run bun run setup again.");
|
|
94
|
+
const saved = await readEnv();
|
|
95
|
+
for (const key of ["HUB_URL", "HUB_API_KEY"]) {
|
|
96
|
+
const value = new RegExp(`^${key}=(.*)$`, "m").exec(saved)?.[1];
|
|
97
|
+
if (value) process.env[key] = value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// What to run when this folder is not signed in and nobody can be asked.
|
|
102
|
+
function loginHelp(problem: string) {
|
|
103
|
+
const hub = process.env.HUB_URL ? "" : " --hub https://<your hub>";
|
|
104
|
+
return `${problem} Sign the folder in, then run bun run setup again:
|
|
105
|
+
|
|
106
|
+
bunx hub-user login${hub}
|
|
107
|
+
|
|
108
|
+
It asks you to paste an API key from the hub's account page, or to approve
|
|
109
|
+
the sign-in in your browser. A coding agent runs it with --browser and shows
|
|
110
|
+
you the link to open.`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// hub-user register --json prints { error, status, forbidden } with exit code
|
|
114
|
+
// 4; forbidden means a 403 (not this account's app), not a login problem.
|
|
115
|
+
function forbidden(output: string) {
|
|
116
|
+
try {
|
|
117
|
+
return (JSON.parse(output) as { forbidden?: boolean }).forbidden === true;
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
56
123
|
// Put back an auth config left aside by an interrupted run.
|
|
57
124
|
if (existsSync(AUTH_CONFIG_ASIDE) && !existsSync(AUTH_CONFIG)) {
|
|
58
125
|
renameSync(AUTH_CONFIG_ASIDE, AUTH_CONFIG);
|
|
59
126
|
}
|
|
60
127
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
128
|
+
// hub-user comes with @user-hub/auth.
|
|
129
|
+
if (!existsSync("node_modules/@user-hub/auth")) {
|
|
130
|
+
fail("Install the dependencies first: bun install");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Sign-in first: nothing below works without it, and a refused key is better
|
|
134
|
+
// found before the Convex project and the questions.
|
|
135
|
+
if (!process.env.HUB_URL || !process.env.HUB_API_KEY) {
|
|
136
|
+
if (!process.stdin.isTTY) {
|
|
137
|
+
fail(loginHelp("This folder is not signed in to the hub."));
|
|
138
|
+
}
|
|
139
|
+
await signIn();
|
|
140
|
+
} else {
|
|
141
|
+
// hub-user whoami exits with 4 when the hub refuses the key.
|
|
142
|
+
const whoami = await hubUser("whoami", "--json");
|
|
143
|
+
if (whoami.code === 4) {
|
|
144
|
+
if (!process.stdin.isTTY) {
|
|
145
|
+
fail(loginHelp("The hub did not accept this folder's API key."));
|
|
146
|
+
}
|
|
147
|
+
console.log("\n The hub did not accept this folder's API key.");
|
|
148
|
+
await signIn();
|
|
149
|
+
} else if (!whoami.ok) {
|
|
150
|
+
process.stderr.write(whoami.errors);
|
|
151
|
+
fail(
|
|
152
|
+
`Could not check this folder's sign-in with ${process.env.HUB_URL}; see the error above.`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
65
155
|
}
|
|
66
156
|
|
|
67
157
|
// 1. Convex project. Its first push happens before the hub values exist, so
|
|
@@ -95,9 +185,11 @@ if (!/^CONVEX_DEPLOYMENT=/m.test(await readEnv())) {
|
|
|
95
185
|
// another one. Once registered, the name is kept in .env.local
|
|
96
186
|
// (HUB_APP_NAME) and later runs update this app's own registration.
|
|
97
187
|
step("Registering this app with User Hub");
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
188
|
+
const packageJson = (await Bun.file("package.json").json()) as {
|
|
189
|
+
name: string;
|
|
190
|
+
scripts: { dev?: string };
|
|
191
|
+
};
|
|
192
|
+
const packageName = packageJson.name;
|
|
101
193
|
// HUB_APP_NAME is written only after a successful registration, so it marks
|
|
102
194
|
// this app's own entry. `bun run setup --name <name>` picks a new name.
|
|
103
195
|
const alreadyRegistered = Boolean(process.env.HUB_APP_NAME);
|
|
@@ -112,23 +204,52 @@ if (!prodUrl && !process.env.HUB_APP_PROD_URL && process.stdin.isTTY) {
|
|
|
112
204
|
" Production URL, where badge scans send people (Enter to skip until you deploy):",
|
|
113
205
|
)?.trim() || undefined;
|
|
114
206
|
}
|
|
207
|
+
// Where the hub opens the app for developers. Sent the first time and with
|
|
208
|
+
// --dev; otherwise the hub keeps the registered one, which HUB_APP_DEV_URL
|
|
209
|
+
// remembers (set by hand with hub-user register, it is not known here).
|
|
210
|
+
const devPort =
|
|
211
|
+
/--port (\d+)/.exec(packageJson.scripts.dev ?? "")?.[1] ?? "3000";
|
|
212
|
+
const devFlag = flag("dev");
|
|
213
|
+
const sendDev = Boolean(devFlag) || !alreadyRegistered;
|
|
214
|
+
const devUrl: string | undefined =
|
|
215
|
+
devFlag ??
|
|
216
|
+
process.env.HUB_APP_DEV_URL ??
|
|
217
|
+
(sendDev ? `http://localhost:${devPort}` : undefined);
|
|
218
|
+
// Passed on to hub-user as is; without either the hub keeps its setting.
|
|
219
|
+
const listing = ["--listed", "--unlisted"].filter((arg) =>
|
|
220
|
+
process.argv.includes(arg),
|
|
221
|
+
);
|
|
222
|
+
if (listing.length > 1) fail("Pass --listed or --unlisted, not both.");
|
|
115
223
|
let registered: Awaited<ReturnType<typeof run>>;
|
|
224
|
+
let signedInAgain = false;
|
|
116
225
|
for (;;) {
|
|
117
|
-
registered = await
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
...(prodUrl ? ["--prod", prodUrl] : []),
|
|
127
|
-
"--json",
|
|
128
|
-
...(alreadyRegistered ? [] : ["--new"]),
|
|
129
|
-
],
|
|
130
|
-
{ capture: true },
|
|
226
|
+
registered = await hubUser(
|
|
227
|
+
"register",
|
|
228
|
+
"--name",
|
|
229
|
+
appName,
|
|
230
|
+
...(sendDev && devUrl ? ["--dev", devUrl] : []),
|
|
231
|
+
...(prodUrl ? ["--prod", prodUrl] : []),
|
|
232
|
+
...listing,
|
|
233
|
+
"--json",
|
|
234
|
+
...(alreadyRegistered ? [] : ["--new"]),
|
|
131
235
|
);
|
|
236
|
+
// hub-user exits with 4 when the hub refuses the API key (401) or this
|
|
237
|
+
// account may not change the app (403); its JSON says which.
|
|
238
|
+
if (registered.code === 4) {
|
|
239
|
+
if (forbidden(registered.output)) {
|
|
240
|
+
fail(`The hub says your account may not change the app "${appName}": it belongs to
|
|
241
|
+
another account, or was registered before accounts and only a hub admin can
|
|
242
|
+
change it. Signing in again does not help. Ask a hub admin, or register this
|
|
243
|
+
app under a new name: ${alreadyRegistered ? `delete HUB_APP_NAME from ${ENV_FILE}, then run ` : ""}bun run setup --name <new name>`);
|
|
244
|
+
}
|
|
245
|
+
if (!process.stdin.isTTY || signedInAgain) {
|
|
246
|
+
fail(loginHelp("The hub did not accept this folder's API key."));
|
|
247
|
+
}
|
|
248
|
+
console.log("\n The hub did not accept this folder's API key.");
|
|
249
|
+
await signIn();
|
|
250
|
+
signedInAgain = true;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
132
253
|
// hub-user exits with 3 when --new finds the name taken.
|
|
133
254
|
if (registered.code !== 3) break;
|
|
134
255
|
console.log(`\n An app called "${appName}" already exists in the hub.`);
|
|
@@ -139,21 +260,42 @@ for (;;) {
|
|
|
139
260
|
if (!appName) fail("No name given. Run bun run setup again.");
|
|
140
261
|
}
|
|
141
262
|
if (!registered.ok) {
|
|
263
|
+
process.stderr.write(registered.errors);
|
|
142
264
|
fail(
|
|
143
265
|
prodUrl
|
|
144
|
-
? "The hub refused the registration; see the error above. Check HUB_URL
|
|
145
|
-
: "The hub refused the registration; see the error above. Check HUB_URL
|
|
266
|
+
? "The hub refused the registration; see the error above. Check HUB_URL and that the production URL is a full https:// address."
|
|
267
|
+
: "The hub refused the registration; see the error above. Check HUB_URL.",
|
|
146
268
|
);
|
|
147
269
|
}
|
|
148
|
-
const { key, hubUrl, env } = JSON.parse(registered.output) as {
|
|
270
|
+
const { key, hubUrl, env, listed } = JSON.parse(registered.output) as {
|
|
149
271
|
key: string;
|
|
150
272
|
hubUrl: string;
|
|
151
273
|
env: { HUB_ISSUER: string; HUB_JWKS: string };
|
|
274
|
+
// The stored setting; missing from hubs without the badge app list.
|
|
275
|
+
listed?: boolean;
|
|
152
276
|
};
|
|
153
277
|
await writeEnv("HUB_APP_NAME", appName);
|
|
154
278
|
if (prodUrl) await writeEnv("HUB_APP_PROD_URL", prodUrl);
|
|
279
|
+
if (sendDev && devUrl) await writeEnv("HUB_APP_DEV_URL", devUrl);
|
|
155
280
|
const production = prodUrl ?? process.env.HUB_APP_PROD_URL;
|
|
156
281
|
console.log(` Registered as "${appName}", app key: ${key}`);
|
|
282
|
+
console.log(
|
|
283
|
+
` Development URL: ${devUrl ?? "the one registered in the hub"}${sendDev ? "" : " (kept; bun run setup --dev <url> changes it)"}`,
|
|
284
|
+
);
|
|
285
|
+
// bun run dev must serve where the hub sends developers back to.
|
|
286
|
+
const devUrlPort = devUrl ? URL.parse(devUrl)?.port : undefined;
|
|
287
|
+
if (devUrlPort && devUrlPort !== devPort) {
|
|
288
|
+
console.log(
|
|
289
|
+
` Note: bun run dev serves port ${devPort} (package.json), not ${devUrlPort}. Change one so they match.`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
if (listed !== undefined) {
|
|
293
|
+
console.log(
|
|
294
|
+
listed
|
|
295
|
+
? ` Listed in the hub's badge app list${production ? "" : " once it has a production URL"} (bun run setup --unlisted hides it)`
|
|
296
|
+
: " Not in the hub's badge app list (bun run setup --listed adds it)",
|
|
297
|
+
);
|
|
298
|
+
}
|
|
157
299
|
|
|
158
300
|
// The key follows the registered name; keep the code in step with it.
|
|
159
301
|
const hubFile = await Bun.file(HUB_FILE).text();
|
|
@@ -195,7 +337,8 @@ if (!(await run(["bunx", "convex", "dev", "--once"])).ok) {
|
|
|
195
337
|
const productionNote = production
|
|
196
338
|
? productionEnvSet
|
|
197
339
|
? `Production: ${production}. Badge scans reach it once the app is scheduled
|
|
198
|
-
or forced live in the hub
|
|
340
|
+
or forced live in the hub${listed ? ", or straight away while badges go to the app list" : ""}.
|
|
341
|
+
Deploy Convex with: bunx convex deploy`
|
|
199
342
|
: `Production: ${production} is registered with the hub, but HUB_ISSUER
|
|
200
343
|
and HUB_JWKS could not be set on the production Convex deployment (see the
|
|
201
344
|
error above). Run bun run setup again before \`bunx convex deploy\`.`
|
|
@@ -211,6 +354,6 @@ console.log(`
|
|
|
211
354
|
|
|
212
355
|
bun run dev
|
|
213
356
|
|
|
214
|
-
Open ${
|
|
357
|
+
Open ${devUrl ?? "the development URL registered in the hub"}: you are sent to the hub to pick who to be, then back signed in.
|
|
215
358
|
|
|
216
359
|
${productionNote}`);
|
package/template/src/router.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
HubSignedIn,
|
|
5
5
|
} from "@user-hub/auth/convex-react";
|
|
6
6
|
import { ConvexReactClient } from "convex/react";
|
|
7
|
+
|
|
7
8
|
import {
|
|
8
9
|
Empty,
|
|
9
10
|
EmptyDescription,
|
|
@@ -11,9 +12,11 @@ import {
|
|
|
11
12
|
EmptyTitle,
|
|
12
13
|
} from "@/components/ui/empty";
|
|
13
14
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
import { APP_KEY } from "../../convex/hub";
|
|
16
17
|
|
|
18
|
+
import appCss from "@/styles.css?url";
|
|
19
|
+
|
|
17
20
|
const CONVEX_URL = import.meta.env.VITE_CONVEX_URL;
|
|
18
21
|
if (!CONVEX_URL) {
|
|
19
22
|
throw new Error("Missing VITE_CONVEX_URL: run `bun run setup` first");
|
|
@@ -2,6 +2,7 @@ import { createFileRoute, Link } from "@tanstack/react-router";
|
|
|
2
2
|
import { useHubUser } from "@user-hub/auth/convex-react";
|
|
3
3
|
import { useQuery } from "convex/react";
|
|
4
4
|
import { ArrowLeftIcon } from "lucide-react";
|
|
5
|
+
|
|
5
6
|
import { Button } from "@/components/ui/button";
|
|
6
7
|
import {
|
|
7
8
|
Card,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
ItemGroup,
|
|
24
25
|
ItemTitle,
|
|
25
26
|
} from "@/components/ui/item";
|
|
27
|
+
|
|
26
28
|
import { api } from "../../convex/_generated/api";
|
|
27
29
|
|
|
28
30
|
export const Route = createFileRoute("/facilitator")({
|
|
@@ -3,6 +3,7 @@ import { useHubSignOut, useHubUser } from "@user-hub/auth/convex-react";
|
|
|
3
3
|
import { useMutation, useQuery } from "convex/react";
|
|
4
4
|
import { LogOutIcon, ShieldIcon } from "lucide-react";
|
|
5
5
|
import { useState } from "react";
|
|
6
|
+
|
|
6
7
|
import { Badge } from "@/components/ui/badge";
|
|
7
8
|
import { Button } from "@/components/ui/button";
|
|
8
9
|
import {
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
ItemGroup,
|
|
29
30
|
ItemTitle,
|
|
30
31
|
} from "@/components/ui/item";
|
|
32
|
+
|
|
31
33
|
import { api } from "../../convex/_generated/api";
|
|
32
34
|
|
|
33
35
|
export const Route = createFileRoute("/")({ component: Home });
|
package/template/vite.config.ts
CHANGED
|
@@ -1,15 +1,60 @@
|
|
|
1
|
-
import babel from "@rolldown/plugin-babel";
|
|
2
1
|
import tailwindcss from "@tailwindcss/vite";
|
|
3
2
|
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
4
|
-
import viteReact
|
|
5
|
-
import { defineConfig } from "vite";
|
|
3
|
+
import viteReact from "@vitejs/plugin-react";
|
|
4
|
+
import { defineConfig, lazyPlugins } from "vite-plus";
|
|
5
|
+
|
|
6
|
+
// Generated, vendored or not ours to touch. Markdown is left exactly as
|
|
7
|
+
// written.
|
|
8
|
+
const ignorePatterns = [
|
|
9
|
+
"**/*.md",
|
|
10
|
+
".agents/**",
|
|
11
|
+
".claude/**",
|
|
12
|
+
"dist/**",
|
|
13
|
+
".tanstack/**",
|
|
14
|
+
"src/routeTree.gen.ts",
|
|
15
|
+
"src/components/ui/**",
|
|
16
|
+
"convex/_generated/**",
|
|
17
|
+
];
|
|
6
18
|
|
|
7
19
|
export default defineConfig({
|
|
8
20
|
resolve: { tsconfigPaths: true },
|
|
9
|
-
plugins: [
|
|
21
|
+
plugins: lazyPlugins(() => [
|
|
10
22
|
tailwindcss(),
|
|
11
23
|
tanstackStart(),
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
],
|
|
24
|
+
// React Compiler, natively (oxc-transform-react) rather than through Babel.
|
|
25
|
+
viteReact({ compiler: true }),
|
|
26
|
+
]),
|
|
27
|
+
// `vp check`: format (Oxfmt), lint (Oxlint) and type-check (tsgolint).
|
|
28
|
+
lint: {
|
|
29
|
+
plugins: ["eslint", "typescript", "unicorn", "oxc"],
|
|
30
|
+
categories: {
|
|
31
|
+
correctness: "error",
|
|
32
|
+
},
|
|
33
|
+
env: {
|
|
34
|
+
builtin: true,
|
|
35
|
+
},
|
|
36
|
+
ignorePatterns,
|
|
37
|
+
options: {
|
|
38
|
+
typeAware: true,
|
|
39
|
+
typeCheck: true,
|
|
40
|
+
},
|
|
41
|
+
overrides: [
|
|
42
|
+
{
|
|
43
|
+
files: ["src/**"],
|
|
44
|
+
plugins: ["react", "jsx-a11y"],
|
|
45
|
+
env: {
|
|
46
|
+
browser: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
fmt: {
|
|
52
|
+
printWidth: 80,
|
|
53
|
+
ignorePatterns,
|
|
54
|
+
sortImports: true,
|
|
55
|
+
sortTailwindcss: {
|
|
56
|
+
stylesheet: "./src/styles.css",
|
|
57
|
+
functions: ["cn", "cva"],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
15
60
|
});
|
package/template/biome.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
|
|
3
|
-
"vcs": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"clientKind": "git",
|
|
6
|
-
"useIgnoreFile": true
|
|
7
|
-
},
|
|
8
|
-
"files": {
|
|
9
|
-
"ignoreUnknown": false,
|
|
10
|
-
"includes": [
|
|
11
|
-
"**",
|
|
12
|
-
"!**/src/routeTree.gen.ts",
|
|
13
|
-
"!**/convex/_generated",
|
|
14
|
-
"!**/.claude",
|
|
15
|
-
"!**/.agents"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"formatter": {
|
|
19
|
-
"enabled": true,
|
|
20
|
-
"indentStyle": "space",
|
|
21
|
-
"indentWidth": 2
|
|
22
|
-
},
|
|
23
|
-
"assist": { "actions": { "source": { "organizeImports": "on" } } },
|
|
24
|
-
"linter": {
|
|
25
|
-
"enabled": true,
|
|
26
|
-
"rules": {
|
|
27
|
-
"preset": "recommended"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"javascript": {
|
|
31
|
-
"formatter": {
|
|
32
|
-
"quoteStyle": "double"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"css": {
|
|
36
|
-
"parser": {
|
|
37
|
-
"tailwindDirectives": true
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"overrides": [
|
|
41
|
-
{
|
|
42
|
-
"includes": ["src/components/ui/**"],
|
|
43
|
-
"linter": { "enabled": false }
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|