create-nextblock 0.8.11 → 0.9.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/bin/create-nextblock.js +101 -35
- package/docker-template/.dockerignore +23 -0
- package/docker-template/.env.docker.example +56 -0
- package/docker-template/Dockerfile +85 -0
- package/docker-template/docker/db/init/99-jwt.sql +6 -0
- package/docker-template/docker/db/init/99-roles.sql +25 -0
- package/docker-template/docker/kong/kong.yml +112 -0
- package/docker-template/docker/migrate/run-migrations.sh +51 -0
- package/docker-template/docker-compose.yml +219 -0
- package/docker-template/scripts/docker-setup.mjs +242 -0
- package/package.json +1 -1
- package/scripts/sync-template.js +29 -0
- package/templates/nextblock-template/.dockerignore +23 -0
- package/templates/nextblock-template/Dockerfile +85 -0
- package/templates/nextblock-template/app/[slug]/page.tsx +5 -0
- package/templates/nextblock-template/app/actions.ts +58 -8
- package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +83 -0
- package/templates/nextblock-template/app/api/upload/presigned-url/route.ts +9 -9
- package/templates/nextblock-template/app/article/[slug]/page.tsx +5 -0
- package/templates/nextblock-template/app/cms/settings/security/actions.ts +30 -0
- package/templates/nextblock-template/app/cms/settings/security/components/SecurityPanel.tsx +69 -0
- package/templates/nextblock-template/app/layout.tsx +57 -3
- package/templates/nextblock-template/app/lib/site-settings.ts +22 -7
- package/templates/nextblock-template/app/page.tsx +6 -0
- package/templates/nextblock-template/app/product/[slug]/page.tsx +5 -0
- package/templates/nextblock-template/app/setup/SetupWizard.tsx +771 -0
- package/templates/nextblock-template/app/setup/layout.tsx +13 -0
- package/templates/nextblock-template/app/setup/page.tsx +103 -0
- package/templates/nextblock-template/components/AppShell.tsx +12 -0
- package/templates/nextblock-template/components/header-auth.tsx +24 -62
- package/templates/nextblock-template/docker/db/init/99-jwt.sql +6 -0
- package/templates/nextblock-template/docker/db/init/99-roles.sql +25 -0
- package/templates/nextblock-template/docker/kong/kong.yml +112 -0
- package/templates/nextblock-template/docker/migrate/run-migrations.sh +51 -0
- package/templates/nextblock-template/docker-compose.yml +219 -0
- package/templates/nextblock-template/docs/11-SELF-HOSTED-DOCKER.md +173 -0
- package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +67 -0
- package/templates/nextblock-template/docs/README.md +2 -0
- package/templates/nextblock-template/lib/blocks/FeaturedProductBlock.tsx +1 -1
- package/templates/nextblock-template/lib/blocks/ProductGridBlock.tsx +1 -1
- package/templates/nextblock-template/lib/custom-block-r2-upload.test.ts +5 -5
- package/templates/nextblock-template/lib/custom-block-r2-upload.ts +2 -2
- package/templates/nextblock-template/lib/setup/actions.ts +370 -0
- package/templates/nextblock-template/lib/setup/env-status.ts +86 -0
- package/templates/nextblock-template/lib/setup/env-write.ts +111 -0
- package/templates/nextblock-template/lib/setup/provisioning.ts +59 -0
- package/templates/nextblock-template/lib/setup/schema-apply.ts +379 -0
- package/templates/nextblock-template/lib/setup/system-config.ts +105 -0
- package/templates/nextblock-template/lib/setup/types.ts +18 -0
- package/templates/nextblock-template/next.config.js +9 -0
- package/templates/nextblock-template/package.json +6 -2
- package/templates/nextblock-template/proxy.ts +143 -49
- package/templates/nextblock-template/scripts/docker-setup.mjs +242 -0
- package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useState, useTransition } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Alert,
|
|
6
|
+
AlertDescription,
|
|
7
|
+
Badge,
|
|
8
|
+
Button,
|
|
9
|
+
Card,
|
|
10
|
+
CardContent,
|
|
11
|
+
CardDescription,
|
|
12
|
+
CardHeader,
|
|
13
|
+
CardTitle,
|
|
14
|
+
Checkbox,
|
|
15
|
+
Input,
|
|
16
|
+
Label,
|
|
17
|
+
Separator,
|
|
18
|
+
Spinner,
|
|
19
|
+
} from '@nextblock-cms/ui';
|
|
20
|
+
import type { DeployChannel } from '../../lib/setup/env-status';
|
|
21
|
+
import { completeSetup, saveSupabaseConnection } from '../../lib/setup/actions';
|
|
22
|
+
import { signInAction } from '../actions';
|
|
23
|
+
|
|
24
|
+
export type StorageKind = 'minio' | 'supabase' | 'r2';
|
|
25
|
+
|
|
26
|
+
export interface StoragePrefill {
|
|
27
|
+
kind: StorageKind;
|
|
28
|
+
readOnly: boolean;
|
|
29
|
+
accountId: string;
|
|
30
|
+
bucket: string;
|
|
31
|
+
endpoint: string;
|
|
32
|
+
publicUrl: string;
|
|
33
|
+
baseUrl: string;
|
|
34
|
+
accessKeyId: string;
|
|
35
|
+
secretAccessKey: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SmtpPrefill {
|
|
39
|
+
host: string;
|
|
40
|
+
port: string;
|
|
41
|
+
user: string;
|
|
42
|
+
fromEmail: string;
|
|
43
|
+
fromName: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Props {
|
|
47
|
+
channel: DeployChannel;
|
|
48
|
+
configured: boolean;
|
|
49
|
+
writable: boolean;
|
|
50
|
+
siteUrl: string;
|
|
51
|
+
storagePrefill: StoragePrefill;
|
|
52
|
+
smtpPrefill: SmtpPrefill;
|
|
53
|
+
turnstilePrefill: { siteKey: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type StepId = 'connection' | 'storage' | 'email' | 'bot' | 'signups' | 'admin';
|
|
57
|
+
|
|
58
|
+
const STEP_TITLES: Record<StepId, string> = {
|
|
59
|
+
connection: 'Database connection',
|
|
60
|
+
storage: 'Media storage',
|
|
61
|
+
email: 'Email (SMTP)',
|
|
62
|
+
bot: 'Bot protection',
|
|
63
|
+
signups: 'Sign-ups',
|
|
64
|
+
admin: 'Administrator account',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const CHANNEL_LABEL: Record<DeployChannel, string> = {
|
|
68
|
+
docker: 'Self-hosted Docker',
|
|
69
|
+
vercel: 'Vercel',
|
|
70
|
+
local: 'Local development',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type Msg = { ok: string } | { err: string } | null;
|
|
74
|
+
|
|
75
|
+
export default function SetupWizard({
|
|
76
|
+
channel,
|
|
77
|
+
configured,
|
|
78
|
+
writable,
|
|
79
|
+
siteUrl,
|
|
80
|
+
storagePrefill,
|
|
81
|
+
smtpPrefill,
|
|
82
|
+
turnstilePrefill,
|
|
83
|
+
}: Props) {
|
|
84
|
+
const [isPending, startTransition] = useTransition();
|
|
85
|
+
const [message, setMessage] = useState<Msg>(null);
|
|
86
|
+
const [phase, setPhase] = useState<'form' | 'working' | 'done'>('form');
|
|
87
|
+
|
|
88
|
+
// Connection (Profile B / local only).
|
|
89
|
+
const [conn, setConn] = useState({
|
|
90
|
+
supabaseUrl: '',
|
|
91
|
+
anonKey: '',
|
|
92
|
+
serviceRoleKey: '',
|
|
93
|
+
postgresUrl: '',
|
|
94
|
+
accessToken: '',
|
|
95
|
+
siteUrl,
|
|
96
|
+
});
|
|
97
|
+
const [connectionDone, setConnectionDone] = useState(configured);
|
|
98
|
+
// "Start from a clean database" — only offered/honored on a local fresh install.
|
|
99
|
+
const [resetFirst, setResetFirst] = useState(true);
|
|
100
|
+
|
|
101
|
+
// Storage / SMTP / bot / signups / admin.
|
|
102
|
+
const [storage, setStorage] = useState(storagePrefill);
|
|
103
|
+
const [smtp, setSmtp] = useState({ ...smtpPrefill, pass: '' });
|
|
104
|
+
const [turnstileEnabled, setTurnstileEnabled] = useState(false);
|
|
105
|
+
const [turnstile, setTurnstile] = useState({
|
|
106
|
+
siteKey: turnstilePrefill.siteKey,
|
|
107
|
+
secretKey: '',
|
|
108
|
+
});
|
|
109
|
+
const [autoAccept, setAutoAccept] = useState(false); // off by default (defense-in-depth)
|
|
110
|
+
const [admin, setAdmin] = useState({ email: '', password: '', fullName: '' });
|
|
111
|
+
|
|
112
|
+
const steps = useMemo<StepId[]>(() => {
|
|
113
|
+
const list: StepId[] = [];
|
|
114
|
+
if (!configured) {
|
|
115
|
+
list.push('connection');
|
|
116
|
+
}
|
|
117
|
+
list.push('storage', 'email', 'bot', 'signups', 'admin');
|
|
118
|
+
return list;
|
|
119
|
+
}, [configured]);
|
|
120
|
+
|
|
121
|
+
const [stepIndex, setStepIndex] = useState(0);
|
|
122
|
+
const current = steps[stepIndex];
|
|
123
|
+
const isLast = stepIndex === steps.length - 1;
|
|
124
|
+
|
|
125
|
+
const setOk = (ok: string) => setMessage({ ok });
|
|
126
|
+
const setErr = (err: string) => setMessage({ err });
|
|
127
|
+
|
|
128
|
+
const goNext = () => {
|
|
129
|
+
setMessage(null);
|
|
130
|
+
setStepIndex((i) => Math.min(i + 1, steps.length - 1));
|
|
131
|
+
};
|
|
132
|
+
const goBack = () => {
|
|
133
|
+
setMessage(null);
|
|
134
|
+
setStepIndex((i) => Math.max(i - 1, 0));
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// --- Step actions ------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
const handleSaveConnection = () => {
|
|
140
|
+
setMessage(null);
|
|
141
|
+
if (!conn.accessToken.trim() && !conn.postgresUrl.trim()) {
|
|
142
|
+
setErr(
|
|
143
|
+
'Provide a Supabase access token (recommended) or a Postgres connection string so the schema can be applied.',
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
startTransition(async () => {
|
|
148
|
+
const result = await saveSupabaseConnection({
|
|
149
|
+
supabaseUrl: conn.supabaseUrl,
|
|
150
|
+
anonKey: conn.anonKey,
|
|
151
|
+
serviceRoleKey: conn.serviceRoleKey,
|
|
152
|
+
postgresUrl: conn.postgresUrl,
|
|
153
|
+
accessToken: conn.accessToken,
|
|
154
|
+
siteUrl: conn.siteUrl,
|
|
155
|
+
});
|
|
156
|
+
if (!result.ok) {
|
|
157
|
+
setErr(result.error ?? 'Could not save the connection.');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
setConnectionDone(true);
|
|
161
|
+
setOk('Connection saved. The database schema is applied automatically when you finish.');
|
|
162
|
+
goNext();
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const handleFinish = () => {
|
|
167
|
+
if (!admin.email || !admin.password) {
|
|
168
|
+
setErr('Enter an administrator email and password.');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (admin.password.length < 8) {
|
|
172
|
+
setErr('Use a password of at least 8 characters.');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const envValues: Record<string, string> = {};
|
|
177
|
+
if (writable && channel === 'local') {
|
|
178
|
+
const put = (k: string, v: string) => {
|
|
179
|
+
if (v && v.trim()) envValues[k] = v.trim();
|
|
180
|
+
};
|
|
181
|
+
put('R2_ACCOUNT_ID', storage.accountId);
|
|
182
|
+
put('R2_BUCKET_NAME', storage.bucket);
|
|
183
|
+
put('R2_ACCESS_KEY_ID', storage.accessKeyId);
|
|
184
|
+
put('R2_SECRET_ACCESS_KEY', storage.secretAccessKey);
|
|
185
|
+
put('NEXT_PUBLIC_R2_PUBLIC_URL', storage.publicUrl);
|
|
186
|
+
put('NEXT_PUBLIC_R2_BASE_URL', storage.baseUrl);
|
|
187
|
+
put('SMTP_HOST', smtp.host);
|
|
188
|
+
put('SMTP_PORT', smtp.port);
|
|
189
|
+
put('SMTP_USER', smtp.user);
|
|
190
|
+
put('SMTP_PASS', smtp.pass);
|
|
191
|
+
put('SMTP_FROM_EMAIL', smtp.fromEmail);
|
|
192
|
+
put('SMTP_FROM_NAME', smtp.fromName);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
setMessage(null);
|
|
196
|
+
setPhase('working');
|
|
197
|
+
startTransition(async () => {
|
|
198
|
+
const result = await completeSetup({
|
|
199
|
+
admin,
|
|
200
|
+
autoAcceptSignups: autoAccept,
|
|
201
|
+
envValues,
|
|
202
|
+
resetFirst: resetFirst && writable,
|
|
203
|
+
turnstile: turnstileEnabled
|
|
204
|
+
? { provider: 'turnstile', siteKey: turnstile.siteKey, secretKey: turnstile.secretKey }
|
|
205
|
+
: { provider: 'none', siteKey: '', secretKey: '' },
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
if (!result.ok) {
|
|
209
|
+
setErr(result.error ?? 'Setup failed.');
|
|
210
|
+
setPhase('form');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Establish the session via the canonical sign-in path (reliable cookie), which
|
|
215
|
+
// redirects into the CMS. With the runtime public-env injection the client works
|
|
216
|
+
// without a dev-server restart.
|
|
217
|
+
const signInData = new FormData();
|
|
218
|
+
signInData.append('email', admin.email.trim());
|
|
219
|
+
signInData.append('password', admin.password);
|
|
220
|
+
await signInAction(signInData);
|
|
221
|
+
|
|
222
|
+
// signInAction redirects on success (and on failure, to /sign-in with a message),
|
|
223
|
+
// so this only runs in the unlikely case it returned without navigating.
|
|
224
|
+
setPhase('done');
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// --- Render ------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
if (phase === 'working') {
|
|
231
|
+
return (
|
|
232
|
+
<div className="space-y-6">
|
|
233
|
+
<SetupProgress willReset={resetFirst && writable} />
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (phase === 'done') {
|
|
239
|
+
return (
|
|
240
|
+
<div className="space-y-6">
|
|
241
|
+
<SetupDone />
|
|
242
|
+
</div>
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const alert =
|
|
247
|
+
message &&
|
|
248
|
+
('ok' in message ? (
|
|
249
|
+
<Alert variant="success" className="py-2 px-4">
|
|
250
|
+
<AlertDescription>{message.ok}</AlertDescription>
|
|
251
|
+
</Alert>
|
|
252
|
+
) : (
|
|
253
|
+
<Alert variant="destructive" className="py-2 px-4">
|
|
254
|
+
<AlertDescription>{message.err}</AlertDescription>
|
|
255
|
+
</Alert>
|
|
256
|
+
));
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<div className="space-y-6">
|
|
260
|
+
<div className="space-y-2 text-center">
|
|
261
|
+
<h1 className="text-2xl font-semibold">Welcome to NextBlock</h1>
|
|
262
|
+
<div className="text-sm text-muted-foreground">
|
|
263
|
+
Let’s get your CMS running. Detected environment:{' '}
|
|
264
|
+
<Badge variant="secondary">{CHANNEL_LABEL[channel]}</Badge>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
<Stepper steps={steps} stepIndex={stepIndex} />
|
|
269
|
+
|
|
270
|
+
<Card>
|
|
271
|
+
<CardHeader>
|
|
272
|
+
<CardTitle>{STEP_TITLES[current]}</CardTitle>
|
|
273
|
+
<CardDescription>{stepDescription(current, channel)}</CardDescription>
|
|
274
|
+
</CardHeader>
|
|
275
|
+
<CardContent className="space-y-5">
|
|
276
|
+
{alert}
|
|
277
|
+
|
|
278
|
+
{current === 'connection' && (
|
|
279
|
+
<div className="space-y-4">
|
|
280
|
+
<Field label="Supabase URL" htmlFor="supabaseUrl">
|
|
281
|
+
<Input
|
|
282
|
+
id="supabaseUrl"
|
|
283
|
+
placeholder="https://YOUR-PROJECT.supabase.co"
|
|
284
|
+
value={conn.supabaseUrl}
|
|
285
|
+
onChange={(e) => setConn({ ...conn, supabaseUrl: e.target.value })}
|
|
286
|
+
/>
|
|
287
|
+
</Field>
|
|
288
|
+
<Field label="Anon (publishable) key" htmlFor="anonKey">
|
|
289
|
+
<Input
|
|
290
|
+
id="anonKey"
|
|
291
|
+
value={conn.anonKey}
|
|
292
|
+
onChange={(e) => setConn({ ...conn, anonKey: e.target.value })}
|
|
293
|
+
/>
|
|
294
|
+
</Field>
|
|
295
|
+
<Field label="Service-role (secret) key" htmlFor="serviceRoleKey">
|
|
296
|
+
<Input
|
|
297
|
+
id="serviceRoleKey"
|
|
298
|
+
type="password"
|
|
299
|
+
value={conn.serviceRoleKey}
|
|
300
|
+
onChange={(e) => setConn({ ...conn, serviceRoleKey: e.target.value })}
|
|
301
|
+
/>
|
|
302
|
+
</Field>
|
|
303
|
+
<Field label="Supabase access token" htmlFor="accessToken">
|
|
304
|
+
<Input
|
|
305
|
+
id="accessToken"
|
|
306
|
+
type="password"
|
|
307
|
+
placeholder="sbp_… (Account → Access Tokens)"
|
|
308
|
+
value={conn.accessToken}
|
|
309
|
+
onChange={(e) => setConn({ ...conn, accessToken: e.target.value })}
|
|
310
|
+
/>
|
|
311
|
+
<p className="text-xs text-muted-foreground">
|
|
312
|
+
Recommended — lets the wizard apply the database schema over HTTPS (works on any
|
|
313
|
+
network, no database host to reach).
|
|
314
|
+
</p>
|
|
315
|
+
</Field>
|
|
316
|
+
<Field label="Postgres connection string (optional)" htmlFor="postgresUrl">
|
|
317
|
+
<Input
|
|
318
|
+
id="postgresUrl"
|
|
319
|
+
placeholder="postgresql://postgres.<ref>:[password]@aws-0-<region>.pooler.supabase.com:5432/postgres"
|
|
320
|
+
value={conn.postgresUrl}
|
|
321
|
+
onChange={(e) => setConn({ ...conn, postgresUrl: e.target.value })}
|
|
322
|
+
/>
|
|
323
|
+
<p className="text-xs text-muted-foreground">
|
|
324
|
+
Fallback used only if no access token is given. Use the <strong>Session pooler</strong>{' '}
|
|
325
|
+
string (Supabase → Connect → Session pooler); the “direct”{' '}
|
|
326
|
+
<code>db.<ref>.supabase.co</code> host fails on IPv4-only networks.
|
|
327
|
+
</p>
|
|
328
|
+
</Field>
|
|
329
|
+
<Field label="Public site URL (optional)" htmlFor="siteUrl">
|
|
330
|
+
<Input
|
|
331
|
+
id="siteUrl"
|
|
332
|
+
placeholder="http://localhost:4200"
|
|
333
|
+
value={conn.siteUrl}
|
|
334
|
+
onChange={(e) => setConn({ ...conn, siteUrl: e.target.value })}
|
|
335
|
+
/>
|
|
336
|
+
</Field>
|
|
337
|
+
{!writable && (
|
|
338
|
+
<Alert variant="destructive" className="py-2 px-4">
|
|
339
|
+
<AlertDescription>
|
|
340
|
+
This environment is read-only. Set the Supabase variables on your hosting
|
|
341
|
+
platform; this step only works in local development.
|
|
342
|
+
</AlertDescription>
|
|
343
|
+
</Alert>
|
|
344
|
+
)}
|
|
345
|
+
</div>
|
|
346
|
+
)}
|
|
347
|
+
|
|
348
|
+
{current === 'storage' && (
|
|
349
|
+
<StorageStep storage={storage} setStorage={setStorage} channel={channel} />
|
|
350
|
+
)}
|
|
351
|
+
|
|
352
|
+
{current === 'email' && (
|
|
353
|
+
<div className="space-y-4">
|
|
354
|
+
{channel === 'docker' && (
|
|
355
|
+
<p className="text-xs text-muted-foreground">
|
|
356
|
+
Docker auto-confirms sign-ups when SMTP is not configured, so this is optional.
|
|
357
|
+
</p>
|
|
358
|
+
)}
|
|
359
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
360
|
+
<Field label="SMTP host" htmlFor="smtpHost">
|
|
361
|
+
<Input
|
|
362
|
+
id="smtpHost"
|
|
363
|
+
value={smtp.host}
|
|
364
|
+
onChange={(e) => setSmtp({ ...smtp, host: e.target.value })}
|
|
365
|
+
/>
|
|
366
|
+
</Field>
|
|
367
|
+
<Field label="Port" htmlFor="smtpPort">
|
|
368
|
+
<Input
|
|
369
|
+
id="smtpPort"
|
|
370
|
+
value={smtp.port}
|
|
371
|
+
onChange={(e) => setSmtp({ ...smtp, port: e.target.value })}
|
|
372
|
+
/>
|
|
373
|
+
</Field>
|
|
374
|
+
<Field label="Username" htmlFor="smtpUser">
|
|
375
|
+
<Input
|
|
376
|
+
id="smtpUser"
|
|
377
|
+
value={smtp.user}
|
|
378
|
+
onChange={(e) => setSmtp({ ...smtp, user: e.target.value })}
|
|
379
|
+
/>
|
|
380
|
+
</Field>
|
|
381
|
+
<Field label="Password" htmlFor="smtpPass">
|
|
382
|
+
<Input
|
|
383
|
+
id="smtpPass"
|
|
384
|
+
type="password"
|
|
385
|
+
value={smtp.pass}
|
|
386
|
+
onChange={(e) => setSmtp({ ...smtp, pass: e.target.value })}
|
|
387
|
+
/>
|
|
388
|
+
</Field>
|
|
389
|
+
<Field label="From email" htmlFor="smtpFromEmail">
|
|
390
|
+
<Input
|
|
391
|
+
id="smtpFromEmail"
|
|
392
|
+
value={smtp.fromEmail}
|
|
393
|
+
onChange={(e) => setSmtp({ ...smtp, fromEmail: e.target.value })}
|
|
394
|
+
/>
|
|
395
|
+
</Field>
|
|
396
|
+
<Field label="From name" htmlFor="smtpFromName">
|
|
397
|
+
<Input
|
|
398
|
+
id="smtpFromName"
|
|
399
|
+
value={smtp.fromName}
|
|
400
|
+
onChange={(e) => setSmtp({ ...smtp, fromName: e.target.value })}
|
|
401
|
+
/>
|
|
402
|
+
</Field>
|
|
403
|
+
</div>
|
|
404
|
+
{!writable && channel !== 'docker' && (
|
|
405
|
+
<p className="text-xs text-muted-foreground">
|
|
406
|
+
On this platform, set SMTP_* as environment variables in your hosting dashboard.
|
|
407
|
+
</p>
|
|
408
|
+
)}
|
|
409
|
+
</div>
|
|
410
|
+
)}
|
|
411
|
+
|
|
412
|
+
{current === 'bot' && (
|
|
413
|
+
<div className="space-y-4">
|
|
414
|
+
<label className="flex items-start gap-3">
|
|
415
|
+
<Checkbox
|
|
416
|
+
checked={turnstileEnabled}
|
|
417
|
+
onCheckedChange={(c) => setTurnstileEnabled(c === true)}
|
|
418
|
+
className="mt-1"
|
|
419
|
+
/>
|
|
420
|
+
<span className="text-sm">
|
|
421
|
+
<span className="font-medium">Enable Cloudflare Turnstile</span>
|
|
422
|
+
<span className="block text-xs text-muted-foreground">
|
|
423
|
+
Protects sign-up / sign-in forms. Stored securely in the database.
|
|
424
|
+
</span>
|
|
425
|
+
</span>
|
|
426
|
+
</label>
|
|
427
|
+
{turnstileEnabled && (
|
|
428
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
429
|
+
<Field label="Site key" htmlFor="tsSite">
|
|
430
|
+
<Input
|
|
431
|
+
id="tsSite"
|
|
432
|
+
value={turnstile.siteKey}
|
|
433
|
+
onChange={(e) => setTurnstile({ ...turnstile, siteKey: e.target.value })}
|
|
434
|
+
/>
|
|
435
|
+
</Field>
|
|
436
|
+
<Field label="Secret key" htmlFor="tsSecret">
|
|
437
|
+
<Input
|
|
438
|
+
id="tsSecret"
|
|
439
|
+
type="password"
|
|
440
|
+
value={turnstile.secretKey}
|
|
441
|
+
onChange={(e) => setTurnstile({ ...turnstile, secretKey: e.target.value })}
|
|
442
|
+
/>
|
|
443
|
+
</Field>
|
|
444
|
+
</div>
|
|
445
|
+
)}
|
|
446
|
+
</div>
|
|
447
|
+
)}
|
|
448
|
+
|
|
449
|
+
{current === 'signups' && (
|
|
450
|
+
<label className="flex items-start gap-3">
|
|
451
|
+
<Checkbox
|
|
452
|
+
checked={autoAccept}
|
|
453
|
+
onCheckedChange={(c) => setAutoAccept(c === true)}
|
|
454
|
+
className="mt-1"
|
|
455
|
+
/>
|
|
456
|
+
<span className="text-sm">
|
|
457
|
+
<span className="font-medium">
|
|
458
|
+
Auto-approve local registrations (skip outbound email verification)
|
|
459
|
+
</span>
|
|
460
|
+
<span className="block text-xs text-muted-foreground">
|
|
461
|
+
New sign-ups become active immediately, even without SMTP configured. Convenient
|
|
462
|
+
for local / self-hosted use; leave off for public production sites.
|
|
463
|
+
</span>
|
|
464
|
+
</span>
|
|
465
|
+
</label>
|
|
466
|
+
)}
|
|
467
|
+
|
|
468
|
+
{current === 'admin' && (
|
|
469
|
+
<div className="space-y-4">
|
|
470
|
+
<Field label="Full name" htmlFor="adminName">
|
|
471
|
+
<Input
|
|
472
|
+
id="adminName"
|
|
473
|
+
value={admin.fullName}
|
|
474
|
+
onChange={(e) => setAdmin({ ...admin, fullName: e.target.value })}
|
|
475
|
+
/>
|
|
476
|
+
</Field>
|
|
477
|
+
<Field label="Email" htmlFor="adminEmail">
|
|
478
|
+
<Input
|
|
479
|
+
id="adminEmail"
|
|
480
|
+
type="email"
|
|
481
|
+
value={admin.email}
|
|
482
|
+
onChange={(e) => setAdmin({ ...admin, email: e.target.value })}
|
|
483
|
+
/>
|
|
484
|
+
</Field>
|
|
485
|
+
<Field label="Password" htmlFor="adminPassword">
|
|
486
|
+
<Input
|
|
487
|
+
id="adminPassword"
|
|
488
|
+
type="password"
|
|
489
|
+
value={admin.password}
|
|
490
|
+
onChange={(e) => setAdmin({ ...admin, password: e.target.value })}
|
|
491
|
+
/>
|
|
492
|
+
</Field>
|
|
493
|
+
<p className="text-xs text-muted-foreground">
|
|
494
|
+
This first account becomes the site administrator, created already-confirmed (no
|
|
495
|
+
verification email needed). Finishing also applies the database schema and saved
|
|
496
|
+
settings, so it can take up to a minute.
|
|
497
|
+
</p>
|
|
498
|
+
|
|
499
|
+
{writable && (
|
|
500
|
+
<label className="flex items-start gap-3 rounded-lg border p-3">
|
|
501
|
+
<Checkbox
|
|
502
|
+
checked={resetFirst}
|
|
503
|
+
onCheckedChange={(c) => setResetFirst(c === true)}
|
|
504
|
+
className="mt-1"
|
|
505
|
+
/>
|
|
506
|
+
<span className="text-sm">
|
|
507
|
+
<span className="font-medium">Start from a clean database</span>
|
|
508
|
+
<span className="block text-xs text-muted-foreground">
|
|
509
|
+
Recommended for a fresh install. Wipes any existing tables, migration history,
|
|
510
|
+
and users in this Supabase project before installing. Uncheck if this database
|
|
511
|
+
already has data you want to keep.
|
|
512
|
+
</span>
|
|
513
|
+
</span>
|
|
514
|
+
</label>
|
|
515
|
+
)}
|
|
516
|
+
</div>
|
|
517
|
+
)}
|
|
518
|
+
|
|
519
|
+
<Separator />
|
|
520
|
+
|
|
521
|
+
<div className="flex items-center justify-between">
|
|
522
|
+
<Button variant="ghost" onClick={goBack} disabled={isPending || stepIndex === 0}>
|
|
523
|
+
Back
|
|
524
|
+
</Button>
|
|
525
|
+
|
|
526
|
+
{current === 'connection' ? (
|
|
527
|
+
<Button onClick={handleSaveConnection} disabled={isPending || !writable}>
|
|
528
|
+
{isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
|
|
529
|
+
Save & verify
|
|
530
|
+
</Button>
|
|
531
|
+
) : isLast ? (
|
|
532
|
+
<Button onClick={handleFinish} disabled={isPending}>
|
|
533
|
+
{isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
|
|
534
|
+
Finish setup
|
|
535
|
+
</Button>
|
|
536
|
+
) : (
|
|
537
|
+
<Button onClick={goNext} disabled={!connectionDone && !configured}>
|
|
538
|
+
Next
|
|
539
|
+
</Button>
|
|
540
|
+
)}
|
|
541
|
+
</div>
|
|
542
|
+
</CardContent>
|
|
543
|
+
</Card>
|
|
544
|
+
</div>
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function stepDescription(step: StepId, channel: DeployChannel): string {
|
|
549
|
+
switch (step) {
|
|
550
|
+
case 'connection':
|
|
551
|
+
return 'Connect this instance to your Supabase project.';
|
|
552
|
+
case 'storage':
|
|
553
|
+
return channel === 'docker'
|
|
554
|
+
? 'Your Docker stack uses MinIO for media storage — already wired up.'
|
|
555
|
+
: channel === 'vercel'
|
|
556
|
+
? 'Using Supabase Storage (S3-compatible) for media.'
|
|
557
|
+
: 'Bring your own Cloudflare R2 bucket for media storage.';
|
|
558
|
+
case 'email':
|
|
559
|
+
return 'Optional. Used for verification emails, password resets, and 2FA codes.';
|
|
560
|
+
case 'bot':
|
|
561
|
+
return 'Optional. Add Cloudflare Turnstile to your auth forms.';
|
|
562
|
+
case 'signups':
|
|
563
|
+
return 'Choose how new public registrations are handled.';
|
|
564
|
+
case 'admin':
|
|
565
|
+
return 'Create the first administrator account.';
|
|
566
|
+
default:
|
|
567
|
+
return '';
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const PROGRESS_MESSAGES = [
|
|
572
|
+
'Laying the foundation blocks…',
|
|
573
|
+
'Seeding the first blocks…',
|
|
574
|
+
'Stacking a few more blocks…',
|
|
575
|
+
'Teaching the blocks to speak (translations)…',
|
|
576
|
+
'Waiting on some stubborn blocks…',
|
|
577
|
+
'Polishing the blocks until they shine…',
|
|
578
|
+
'Almost there — slotting in the last blocks…',
|
|
579
|
+
];
|
|
580
|
+
|
|
581
|
+
function SetupProgress({ willReset }: { willReset: boolean }) {
|
|
582
|
+
const messages = willReset
|
|
583
|
+
? ['Wiping the old blocks away…', ...PROGRESS_MESSAGES]
|
|
584
|
+
: PROGRESS_MESSAGES;
|
|
585
|
+
const [pct, setPct] = useState(8);
|
|
586
|
+
const [msgIndex, setMsgIndex] = useState(0);
|
|
587
|
+
|
|
588
|
+
useEffect(() => {
|
|
589
|
+
// Indeterminate work (one server action) shown as a friendly creeping bar that eases
|
|
590
|
+
// toward ~92% and a rotating set of block-themed messages.
|
|
591
|
+
const progress = setInterval(() => {
|
|
592
|
+
setPct((value) => (value >= 92 ? 92 : value + Math.max(1, Math.round((96 - value) / 14))));
|
|
593
|
+
}, 700);
|
|
594
|
+
const cycle = setInterval(() => {
|
|
595
|
+
setMsgIndex((index) => (index + 1) % messages.length);
|
|
596
|
+
}, 2200);
|
|
597
|
+
return () => {
|
|
598
|
+
clearInterval(progress);
|
|
599
|
+
clearInterval(cycle);
|
|
600
|
+
};
|
|
601
|
+
}, [messages.length]);
|
|
602
|
+
|
|
603
|
+
return (
|
|
604
|
+
<Card>
|
|
605
|
+
<CardHeader>
|
|
606
|
+
<CardTitle>Building your NextBlock…</CardTitle>
|
|
607
|
+
<CardDescription>
|
|
608
|
+
{willReset ? 'Resetting the database, then applying' : 'Applying'} the schema, seeding
|
|
609
|
+
content, and creating your account. This can take a minute — hang tight.
|
|
610
|
+
</CardDescription>
|
|
611
|
+
</CardHeader>
|
|
612
|
+
<CardContent className="space-y-4">
|
|
613
|
+
<div className="h-2 w-full overflow-hidden rounded-full bg-muted">
|
|
614
|
+
<div
|
|
615
|
+
className="h-full rounded-full bg-primary transition-all duration-700 ease-out"
|
|
616
|
+
style={{ width: `${pct}%` }}
|
|
617
|
+
/>
|
|
618
|
+
</div>
|
|
619
|
+
<p className="text-sm text-muted-foreground">{messages[msgIndex]}</p>
|
|
620
|
+
</CardContent>
|
|
621
|
+
</Card>
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function SetupDone() {
|
|
626
|
+
return (
|
|
627
|
+
<Card>
|
|
628
|
+
<CardHeader>
|
|
629
|
+
<CardTitle>🎉 Setup complete!</CardTitle>
|
|
630
|
+
<CardDescription>
|
|
631
|
+
Your administrator account is ready and the database is seeded.
|
|
632
|
+
</CardDescription>
|
|
633
|
+
</CardHeader>
|
|
634
|
+
<CardContent>
|
|
635
|
+
<Button onClick={() => (window.location.href = '/cms/dashboard')}>Enter your CMS</Button>
|
|
636
|
+
</CardContent>
|
|
637
|
+
</Card>
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function Stepper({
|
|
642
|
+
steps,
|
|
643
|
+
stepIndex,
|
|
644
|
+
}: {
|
|
645
|
+
steps: StepId[];
|
|
646
|
+
stepIndex: number;
|
|
647
|
+
}) {
|
|
648
|
+
return (
|
|
649
|
+
<ol className="flex flex-wrap items-center justify-center gap-2 text-xs">
|
|
650
|
+
{steps.map((s, i) => (
|
|
651
|
+
<li
|
|
652
|
+
key={s}
|
|
653
|
+
className={`flex items-center gap-2 rounded-full border px-3 py-1 ${
|
|
654
|
+
i === stepIndex
|
|
655
|
+
? 'border-primary text-primary'
|
|
656
|
+
: i < stepIndex
|
|
657
|
+
? 'border-muted text-muted-foreground'
|
|
658
|
+
: 'border-muted text-muted-foreground/60'
|
|
659
|
+
}`}
|
|
660
|
+
>
|
|
661
|
+
<span className="font-medium">{i + 1}</span>
|
|
662
|
+
<span>{STEP_TITLES[s]}</span>
|
|
663
|
+
</li>
|
|
664
|
+
))}
|
|
665
|
+
</ol>
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function StorageStep({
|
|
670
|
+
storage,
|
|
671
|
+
setStorage,
|
|
672
|
+
channel,
|
|
673
|
+
}: {
|
|
674
|
+
storage: StoragePrefill;
|
|
675
|
+
setStorage: (s: StoragePrefill) => void;
|
|
676
|
+
channel: DeployChannel;
|
|
677
|
+
}) {
|
|
678
|
+
if (channel === 'docker') {
|
|
679
|
+
return (
|
|
680
|
+
<div className="space-y-3 text-sm">
|
|
681
|
+
<Alert variant="success" className="py-2 px-4">
|
|
682
|
+
<AlertDescription>
|
|
683
|
+
MinIO is already configured by the Docker setup. Nothing to do here.
|
|
684
|
+
</AlertDescription>
|
|
685
|
+
</Alert>
|
|
686
|
+
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
|
687
|
+
<dt>Endpoint</dt>
|
|
688
|
+
<dd className="font-mono">{storage.endpoint}</dd>
|
|
689
|
+
<dt>Bucket</dt>
|
|
690
|
+
<dd className="font-mono">{storage.bucket}</dd>
|
|
691
|
+
<dt>Public URL</dt>
|
|
692
|
+
<dd className="font-mono">{storage.publicUrl}</dd>
|
|
693
|
+
</dl>
|
|
694
|
+
</div>
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return (
|
|
699
|
+
<div className="space-y-4">
|
|
700
|
+
{channel === 'vercel' && (
|
|
701
|
+
<p className="text-xs text-muted-foreground">
|
|
702
|
+
Pre-filled for Supabase Storage. Create an S3 access key in your Supabase project
|
|
703
|
+
(Storage → S3 connection) and set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY in your Vercel
|
|
704
|
+
environment.
|
|
705
|
+
</p>
|
|
706
|
+
)}
|
|
707
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
708
|
+
<Field label="Account / provider id" htmlFor="r2Account">
|
|
709
|
+
<Input
|
|
710
|
+
id="r2Account"
|
|
711
|
+
value={storage.accountId}
|
|
712
|
+
onChange={(e) => setStorage({ ...storage, accountId: e.target.value })}
|
|
713
|
+
/>
|
|
714
|
+
</Field>
|
|
715
|
+
<Field label="Bucket" htmlFor="r2Bucket">
|
|
716
|
+
<Input
|
|
717
|
+
id="r2Bucket"
|
|
718
|
+
value={storage.bucket}
|
|
719
|
+
onChange={(e) => setStorage({ ...storage, bucket: e.target.value })}
|
|
720
|
+
/>
|
|
721
|
+
</Field>
|
|
722
|
+
<Field label="Access key id" htmlFor="r2Access">
|
|
723
|
+
<Input
|
|
724
|
+
id="r2Access"
|
|
725
|
+
value={storage.accessKeyId}
|
|
726
|
+
onChange={(e) => setStorage({ ...storage, accessKeyId: e.target.value })}
|
|
727
|
+
/>
|
|
728
|
+
</Field>
|
|
729
|
+
<Field label="Secret access key" htmlFor="r2Secret">
|
|
730
|
+
<Input
|
|
731
|
+
id="r2Secret"
|
|
732
|
+
type="password"
|
|
733
|
+
value={storage.secretAccessKey}
|
|
734
|
+
onChange={(e) => setStorage({ ...storage, secretAccessKey: e.target.value })}
|
|
735
|
+
/>
|
|
736
|
+
</Field>
|
|
737
|
+
<Field label="Public URL" htmlFor="r2Public">
|
|
738
|
+
<Input
|
|
739
|
+
id="r2Public"
|
|
740
|
+
value={storage.publicUrl}
|
|
741
|
+
onChange={(e) => setStorage({ ...storage, publicUrl: e.target.value })}
|
|
742
|
+
/>
|
|
743
|
+
</Field>
|
|
744
|
+
<Field label="Custom domain (optional)" htmlFor="r2Base">
|
|
745
|
+
<Input
|
|
746
|
+
id="r2Base"
|
|
747
|
+
value={storage.baseUrl}
|
|
748
|
+
onChange={(e) => setStorage({ ...storage, baseUrl: e.target.value })}
|
|
749
|
+
/>
|
|
750
|
+
</Field>
|
|
751
|
+
</div>
|
|
752
|
+
</div>
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function Field({
|
|
757
|
+
label,
|
|
758
|
+
htmlFor,
|
|
759
|
+
children,
|
|
760
|
+
}: {
|
|
761
|
+
label: string;
|
|
762
|
+
htmlFor: string;
|
|
763
|
+
children: React.ReactNode;
|
|
764
|
+
}) {
|
|
765
|
+
return (
|
|
766
|
+
<div className="space-y-1.5">
|
|
767
|
+
<Label htmlFor={htmlFor}>{label}</Label>
|
|
768
|
+
{children}
|
|
769
|
+
</div>
|
|
770
|
+
);
|
|
771
|
+
}
|