create-user-hub 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/.env.example +1 -1
- package/template/CLAUDE.md +1 -1
- package/template/README.md +1 -0
- package/template/scripts/setup.ts +59 -10
package/package.json
CHANGED
package/template/.env.example
CHANGED
package/template/CLAUDE.md
CHANGED
|
@@ -21,4 +21,4 @@ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan the
|
|
|
21
21
|
|
|
22
22
|
## Commands
|
|
23
23
|
|
|
24
|
-
`bun run setup` (once), `bun run dev`, `bun run check`, `bun run typecheck`, `bun run build`.
|
|
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`, `bun run typecheck`, `bun run build`.
|
package/template/README.md
CHANGED
|
@@ -13,6 +13,7 @@ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and
|
|
|
13
13
|
|
|
14
14
|
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>`). Safe to run again.
|
|
15
15
|
3. `bun run dev`, then open http://localhost:3000. You are sent to the hub to pick who to be, then back signed in.
|
|
16
|
+
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.
|
|
16
17
|
|
|
17
18
|
## What's inside
|
|
18
19
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Run: bun run setup [--name <name>]. Safe to run again
|
|
1
|
+
// Setup: creates the Convex project, registers this app with User Hub and
|
|
2
|
+
// sets the values that make Convex trust the hub's tokens.
|
|
3
|
+
// Run: bun run setup [--name <name>] [--prod <url>]. Safe to run again; run
|
|
4
|
+
// it with --prod once the app is deployed so badge scans can reach it.
|
|
4
5
|
// Needs HUB_URL and HUB_ADMIN_PASSWORD in .env.local (Bun loads it).
|
|
5
6
|
|
|
6
7
|
import { existsSync, renameSync } from "node:fs";
|
|
@@ -12,6 +13,12 @@ const DEV_URL = "http://localhost:3000";
|
|
|
12
13
|
const AUTH_CONFIG = "convex/auth.config.ts";
|
|
13
14
|
const AUTH_CONFIG_ASIDE = "convex/auth.config.ts.setup";
|
|
14
15
|
|
|
16
|
+
// The value after --flag on the command line, if any.
|
|
17
|
+
function flag(name: string) {
|
|
18
|
+
const at = process.argv.indexOf(`--${name}`);
|
|
19
|
+
return at > -1 ? process.argv[at + 1]?.trim() || undefined : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
function step(message: string) {
|
|
16
23
|
console.log(`\n▸ ${message}`);
|
|
17
24
|
}
|
|
@@ -93,12 +100,18 @@ const packageName = (
|
|
|
93
100
|
).name;
|
|
94
101
|
// HUB_APP_NAME is written only after a successful registration, so it marks
|
|
95
102
|
// this app's own entry. `bun run setup --name <name>` picks a new name.
|
|
96
|
-
const nameFlag = process.argv.indexOf("--name");
|
|
97
103
|
const alreadyRegistered = Boolean(process.env.HUB_APP_NAME);
|
|
98
|
-
let appName =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
let appName = process.env.HUB_APP_NAME ?? flag("name") ?? packageName;
|
|
105
|
+
|
|
106
|
+
// Where badge scans send people. Asked once in a terminal; skipped until the
|
|
107
|
+
// app is deployed, then added with --prod. HUB_APP_PROD_URL remembers it.
|
|
108
|
+
let prodUrl = flag("prod");
|
|
109
|
+
if (!prodUrl && !process.env.HUB_APP_PROD_URL && process.stdin.isTTY) {
|
|
110
|
+
prodUrl =
|
|
111
|
+
prompt(
|
|
112
|
+
" Production URL, where badge scans send people (Enter to skip until you deploy):",
|
|
113
|
+
)?.trim() || undefined;
|
|
114
|
+
}
|
|
102
115
|
let registered: Awaited<ReturnType<typeof run>>;
|
|
103
116
|
for (;;) {
|
|
104
117
|
registered = await run(
|
|
@@ -110,6 +123,7 @@ for (;;) {
|
|
|
110
123
|
appName,
|
|
111
124
|
"--dev",
|
|
112
125
|
DEV_URL,
|
|
126
|
+
...(prodUrl ? ["--prod", prodUrl] : []),
|
|
113
127
|
"--json",
|
|
114
128
|
...(alreadyRegistered ? [] : ["--new"]),
|
|
115
129
|
],
|
|
@@ -126,7 +140,9 @@ for (;;) {
|
|
|
126
140
|
}
|
|
127
141
|
if (!registered.ok) {
|
|
128
142
|
fail(
|
|
129
|
-
|
|
143
|
+
prodUrl
|
|
144
|
+
? "The hub refused the registration; see the error above. Check HUB_URL, HUB_ADMIN_PASSWORD and that the production URL is a full https:// address."
|
|
145
|
+
: "The hub refused the registration; see the error above. Check HUB_URL and HUB_ADMIN_PASSWORD.",
|
|
130
146
|
);
|
|
131
147
|
}
|
|
132
148
|
const { key, hubUrl, env } = JSON.parse(registered.output) as {
|
|
@@ -135,6 +151,8 @@ const { key, hubUrl, env } = JSON.parse(registered.output) as {
|
|
|
135
151
|
env: { HUB_ISSUER: string; HUB_JWKS: string };
|
|
136
152
|
};
|
|
137
153
|
await writeEnv("HUB_APP_NAME", appName);
|
|
154
|
+
if (prodUrl) await writeEnv("HUB_APP_PROD_URL", prodUrl);
|
|
155
|
+
const production = prodUrl ?? process.env.HUB_APP_PROD_URL;
|
|
138
156
|
console.log(` Registered as "${appName}", app key: ${key}`);
|
|
139
157
|
|
|
140
158
|
// The key follows the registered name; keep the code in step with it.
|
|
@@ -153,15 +171,46 @@ for (const [variable, value] of Object.entries(env)) {
|
|
|
153
171
|
}
|
|
154
172
|
await writeEnv("VITE_HUB_URL", hubUrl);
|
|
155
173
|
|
|
174
|
+
// The production Convex deployment needs the same two values once the app is
|
|
175
|
+
// deployed. It may not exist yet: then say how to set them later.
|
|
176
|
+
let productionEnvSet = false;
|
|
177
|
+
if (production) {
|
|
178
|
+
step("Setting HUB_ISSUER and HUB_JWKS on the production Convex deployment");
|
|
179
|
+
productionEnvSet = true;
|
|
180
|
+
for (const [variable, value] of Object.entries(env)) {
|
|
181
|
+
const result = await run(
|
|
182
|
+
["bunx", "convex", "env", "set", "--prod", variable, value],
|
|
183
|
+
{ capture: true },
|
|
184
|
+
);
|
|
185
|
+
productionEnvSet &&= result.ok;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
156
189
|
// 4. Push the functions now that auth is configured.
|
|
157
190
|
step("Deploying the Convex functions");
|
|
158
191
|
if (!(await run(["bunx", "convex", "dev", "--once"])).ok) {
|
|
159
192
|
fail("Convex did not accept the functions; see the error above.");
|
|
160
193
|
}
|
|
161
194
|
|
|
195
|
+
const productionNote = production
|
|
196
|
+
? productionEnvSet
|
|
197
|
+
? `Production: ${production}. Badge scans reach it once the app is scheduled
|
|
198
|
+
or forced live in the hub. Deploy Convex with: bunx convex deploy`
|
|
199
|
+
: `Production: ${production} is registered with the hub, but HUB_ISSUER
|
|
200
|
+
and HUB_JWKS could not be set on the production Convex deployment (see the
|
|
201
|
+
error above). Run bun run setup again before \`bunx convex deploy\`.`
|
|
202
|
+
: `No production URL yet, so badge scans cannot reach this app. Once it is
|
|
203
|
+
deployed, run:
|
|
204
|
+
|
|
205
|
+
bun run setup --prod https://your-app.example.com
|
|
206
|
+
|
|
207
|
+
(or ask your coding agent to set up the production URL).`;
|
|
208
|
+
|
|
162
209
|
console.log(`
|
|
163
210
|
✓ Ready. Start the app:
|
|
164
211
|
|
|
165
212
|
bun run dev
|
|
166
213
|
|
|
167
|
-
Open ${DEV_URL}: you are sent to the hub to pick who to be, then back signed in
|
|
214
|
+
Open ${DEV_URL}: you are sent to the hub to pick who to be, then back signed in.
|
|
215
|
+
|
|
216
|
+
${productionNote}`);
|