create-nextblock 0.14.0 → 0.14.2

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.
Files changed (242) hide show
  1. package/docker-template/.dockerignore +23 -23
  2. package/docker-template/.env.docker.example +69 -69
  3. package/docker-template/docker/db/init/99-jwt.sql +6 -6
  4. package/docker-template/docker/db/init/99-roles.sql +25 -25
  5. package/docker-template/docker/kong/kong.yml +112 -112
  6. package/docker-template/scripts/docker-setup.mjs +310 -310
  7. package/libs/db/tsconfig.lib.json +3 -3
  8. package/libs/editor/tsconfig.lib.json +3 -3
  9. package/libs/ui/tsconfig.lib.json +3 -3
  10. package/libs/utils/tsconfig.json +3 -3
  11. package/package.json +1 -1
  12. package/project.json +19 -19
  13. package/templates/nextblock-template/.browserslistrc +11 -11
  14. package/templates/nextblock-template/.dockerignore +23 -23
  15. package/templates/nextblock-template/README.md +34 -34
  16. package/templates/nextblock-template/app/(auth-pages)/layout.tsx +9 -9
  17. package/templates/nextblock-template/app/(auth-pages)/post-sign-in/page.tsx +27 -27
  18. package/templates/nextblock-template/app/(auth-pages)/sign-up/page.tsx +46 -46
  19. package/templates/nextblock-template/app/(auth-pages)/two-factor/page.tsx +51 -51
  20. package/templates/nextblock-template/app/ToasterProvider.tsx +17 -17
  21. package/templates/nextblock-template/app/[slug]/pageClientActions.ts +7 -7
  22. package/templates/nextblock-template/app/actions/consent.ts +57 -57
  23. package/templates/nextblock-template/app/actions/postActions.ts +146 -146
  24. package/templates/nextblock-template/app/actions/twoFactorEmail.ts +22 -22
  25. package/templates/nextblock-template/app/api/ai/cortex/build-widget/route.ts +153 -153
  26. package/templates/nextblock-template/app/api/ai/generate-blocks/route.ts +96 -96
  27. package/templates/nextblock-template/app/api/brand/email-logo/route.ts +48 -48
  28. package/templates/nextblock-template/app/api/cms/check-updates/route.ts +44 -44
  29. package/templates/nextblock-template/app/api/cms/full-backup/export/route.ts +33 -33
  30. package/templates/nextblock-template/app/api/cms/full-backup/restore/route.ts +63 -63
  31. package/templates/nextblock-template/app/api/cron/reset-sandbox/route.ts +3490 -3490
  32. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +5749 -5749
  33. package/templates/nextblock-template/app/api/cron/sync-currencies/route.ts +39 -39
  34. package/templates/nextblock-template/app/api/custom-blocks/db-relations/route.ts +92 -92
  35. package/templates/nextblock-template/app/api/custom-blocks/editor-definitions/route.ts +43 -43
  36. package/templates/nextblock-template/app/api/media/library/route.ts +69 -69
  37. package/templates/nextblock-template/app/api/media/r2-presigned/route.ts +53 -53
  38. package/templates/nextblock-template/app/api/media/record/route.ts +160 -160
  39. package/templates/nextblock-template/app/api/search/route.ts +43 -43
  40. package/templates/nextblock-template/app/article/[slug]/PostClientContent.tsx +441 -441
  41. package/templates/nextblock-template/app/auth/callback/route.ts +31 -31
  42. package/templates/nextblock-template/app/cart/page.tsx +7 -7
  43. package/templates/nextblock-template/app/cms/blocks/components/CustomBlockEditorPreview.tsx +160 -160
  44. package/templates/nextblock-template/app/cms/blocks/components/MediaLibraryModal.tsx +149 -149
  45. package/templates/nextblock-template/app/cms/blocks/editors/DynamicCustomBlockEditor.tsx +167 -167
  46. package/templates/nextblock-template/app/cms/blocks/editors/ImageBlockEditor.tsx +4 -2
  47. package/templates/nextblock-template/app/cms/blocks/editors/TextBlockEditor.tsx +90 -90
  48. package/templates/nextblock-template/app/cms/components/ConnectGitHubButton.tsx +122 -122
  49. package/templates/nextblock-template/app/cms/components/CortexAiPageContext.tsx +58 -58
  50. package/templates/nextblock-template/app/cms/components/FeedbackModal.tsx +36 -36
  51. package/templates/nextblock-template/app/cms/components/SystemAlertsBanner.tsx +112 -112
  52. package/templates/nextblock-template/app/cms/components/TwoFactorReminderBanner.tsx +45 -45
  53. package/templates/nextblock-template/app/cms/components/github-connect-actions.ts +102 -102
  54. package/templates/nextblock-template/app/cms/components/system-alerts-actions.ts +31 -31
  55. package/templates/nextblock-template/app/cms/custom-blocks/[id]/edit/page.tsx +66 -66
  56. package/templates/nextblock-template/app/cms/custom-blocks/actions.ts +519 -519
  57. package/templates/nextblock-template/app/cms/custom-blocks/components/BlocksLibraryTransferControls.tsx +256 -256
  58. package/templates/nextblock-template/app/cms/custom-blocks/components/DBRelationSelect.tsx +384 -384
  59. package/templates/nextblock-template/app/cms/custom-blocks/components/ImageR2Picker.tsx +221 -221
  60. package/templates/nextblock-template/app/cms/custom-blocks/new/page.tsx +12 -12
  61. package/templates/nextblock-template/app/cms/custom-blocks/page.tsx +438 -438
  62. package/templates/nextblock-template/app/cms/dashboard/actions.ts +228 -228
  63. package/templates/nextblock-template/app/cms/dashboard/components/DashboardOnboarding.tsx +130 -130
  64. package/templates/nextblock-template/app/cms/import-export/actions.ts +226 -226
  65. package/templates/nextblock-template/app/cms/layout.tsx +73 -73
  66. package/templates/nextblock-template/app/cms/media/components/FolderNavigator.tsx +273 -273
  67. package/templates/nextblock-template/app/cms/media/components/FolderTree.tsx +122 -122
  68. package/templates/nextblock-template/app/cms/media/components/MediaEditForm.tsx +26 -26
  69. package/templates/nextblock-template/app/cms/media/components/MediaGridClient.tsx +69 -69
  70. package/templates/nextblock-template/app/cms/navigation/components/NavigationMenuDnd.tsx +3 -3
  71. package/templates/nextblock-template/app/cms/products/attributes/page.tsx +12 -12
  72. package/templates/nextblock-template/app/cms/products/categories/page.tsx +12 -12
  73. package/templates/nextblock-template/app/cms/products/inventory/page.tsx +13 -13
  74. package/templates/nextblock-template/app/cms/products/new/page.tsx +135 -135
  75. package/templates/nextblock-template/app/cms/products/productFormData.ts +133 -133
  76. package/templates/nextblock-template/app/cms/products/settings/page.tsx +5 -5
  77. package/templates/nextblock-template/app/cms/promotions/PromotionsWorkspace.tsx +456 -456
  78. package/templates/nextblock-template/app/cms/promotions/actions.ts +115 -115
  79. package/templates/nextblock-template/app/cms/promotions/page.tsx +31 -31
  80. package/templates/nextblock-template/app/cms/revisions/service.ts +19 -19
  81. package/templates/nextblock-template/app/cms/revisions/utils.ts +132 -132
  82. package/templates/nextblock-template/app/cms/settings/backup-restore/BackupRestoreWorkspace.tsx +1004 -1004
  83. package/templates/nextblock-template/app/cms/settings/backup-restore/page.tsx +29 -29
  84. package/templates/nextblock-template/app/cms/settings/bot-protection/page.tsx +24 -24
  85. package/templates/nextblock-template/app/cms/settings/cortex-ai/SandboxCortexAiSettingsClient.tsx +688 -688
  86. package/templates/nextblock-template/app/cms/settings/currencies/actions.ts +331 -331
  87. package/templates/nextblock-template/app/cms/settings/currencies/page.tsx +494 -494
  88. package/templates/nextblock-template/app/cms/settings/email/page.tsx +28 -28
  89. package/templates/nextblock-template/app/cms/settings/extra-translations/ExtraTranslationsWorkspace.tsx +767 -767
  90. package/templates/nextblock-template/app/cms/settings/extra-translations/page.tsx +93 -93
  91. package/templates/nextblock-template/app/cms/settings/google-analytics/page.tsx +26 -26
  92. package/templates/nextblock-template/app/cms/settings/logos/[id]/edit/page.tsx +7 -7
  93. package/templates/nextblock-template/app/cms/settings/logos/components/BrandingSettingsForm.tsx +339 -339
  94. package/templates/nextblock-template/app/cms/settings/logos/components/DeleteLogoButton.tsx +21 -21
  95. package/templates/nextblock-template/app/cms/settings/logos/components/LogoForm.tsx +23 -21
  96. package/templates/nextblock-template/app/cms/settings/logos/components/SetActiveLogoButton.tsx +42 -42
  97. package/templates/nextblock-template/app/cms/settings/logos/components/SiteSeoSettingsForm.tsx +133 -133
  98. package/templates/nextblock-template/app/cms/settings/logos/new/page.tsx +8 -8
  99. package/templates/nextblock-template/app/cms/settings/packages/package-card.tsx +122 -122
  100. package/templates/nextblock-template/app/cms/settings/privacy/page.tsx +27 -27
  101. package/templates/nextblock-template/app/cms/settings/registration/page.tsx +27 -27
  102. package/templates/nextblock-template/app/cms/settings/security/components/SecurityPanel.tsx +9 -7
  103. package/templates/nextblock-template/app/cms/settings/security/page.tsx +33 -33
  104. package/templates/nextblock-template/app/cms/settings/taxes/page.tsx +21 -21
  105. package/templates/nextblock-template/app/cms/shipping/page.tsx +20 -20
  106. package/templates/nextblock-template/app/cms/users/components/DeleteUserButton.tsx +12 -12
  107. package/templates/nextblock-template/app/lib/site-settings.ts +105 -105
  108. package/templates/nextblock-template/app/profile/ProfilePageHeader.tsx +16 -16
  109. package/templates/nextblock-template/app/profile/ProfilePageMissingState.tsx +9 -9
  110. package/templates/nextblock-template/app/profile/account-links.ts +22 -22
  111. package/templates/nextblock-template/app/profile/orders/CustomerOrdersPageClient.tsx +124 -124
  112. package/templates/nextblock-template/app/profile/orders/page.tsx +19 -19
  113. package/templates/nextblock-template/app/profile/password/PasswordSettingsPageClient.tsx +128 -128
  114. package/templates/nextblock-template/app/profile/password/actions.ts +59 -59
  115. package/templates/nextblock-template/app/profile/password/page.tsx +27 -27
  116. package/templates/nextblock-template/app/setup/SetupWizard.tsx +678 -678
  117. package/templates/nextblock-template/app/setup/layout.tsx +13 -13
  118. package/templates/nextblock-template/app/setup/page.tsx +111 -111
  119. package/templates/nextblock-template/app/sitemap.ts +130 -130
  120. package/templates/nextblock-template/components/CartDrawerLoader.tsx +7 -7
  121. package/templates/nextblock-template/components/DeferredCartDrawer.tsx +23 -23
  122. package/templates/nextblock-template/components/DeferredGoogleAnalytics.tsx +70 -70
  123. package/templates/nextblock-template/components/DeferredGoogleTagManager.tsx +70 -70
  124. package/templates/nextblock-template/components/DeferredSpeedInsights.tsx +69 -69
  125. package/templates/nextblock-template/components/FeatureImageHero.tsx +47 -47
  126. package/templates/nextblock-template/components/FooterNavigation.tsx +32 -32
  127. package/templates/nextblock-template/components/HtmlScriptExecutor.tsx +47 -47
  128. package/templates/nextblock-template/components/LanguageSwitcher.tsx +2 -2
  129. package/templates/nextblock-template/components/PublicEnvBootstrap.tsx +30 -30
  130. package/templates/nextblock-template/components/ResponsiveNav.tsx +14 -14
  131. package/templates/nextblock-template/components/auth/AuthBotProtection.tsx +182 -182
  132. package/templates/nextblock-template/components/blocks/PostCardSkeleton.tsx +12 -12
  133. package/templates/nextblock-template/components/blocks/PostsGridBlock.tsx +12 -12
  134. package/templates/nextblock-template/components/blocks/ecommerceRendererLoaders.ts +23 -23
  135. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +249 -249
  136. package/templates/nextblock-template/components/blocks/types.ts +7 -7
  137. package/templates/nextblock-template/components/env-var-warning.tsx +3 -3
  138. package/templates/nextblock-template/components/form-message.tsx +32 -32
  139. package/templates/nextblock-template/components/media/YouTubeFacade.tsx +105 -105
  140. package/templates/nextblock-template/components/media/youtube-embed-replace.tsx +32 -32
  141. package/templates/nextblock-template/components/privacy/ConsentBanner.tsx +170 -170
  142. package/templates/nextblock-template/components/privacy/ConsentGatedAnalytics.tsx +70 -70
  143. package/templates/nextblock-template/components/renderers/CachedDynamicLayoutEngine.tsx +28 -28
  144. package/templates/nextblock-template/components/renderers/DynamicLayoutEngine.test.tsx +166 -166
  145. package/templates/nextblock-template/components/renderers/DynamicLayoutEngine.tsx +471 -471
  146. package/templates/nextblock-template/components/submit-button.tsx +23 -23
  147. package/templates/nextblock-template/components/theme-switcher.tsx +8 -8
  148. package/templates/nextblock-template/components/visual-editing/DeferredVisualEditing.tsx +21 -21
  149. package/templates/nextblock-template/context/AuthContext.tsx +23 -23
  150. package/templates/nextblock-template/context/language-rest-client.ts +32 -32
  151. package/templates/nextblock-template/docker/db/init/99-jwt.sql +6 -6
  152. package/templates/nextblock-template/docker/db/init/99-roles.sql +25 -25
  153. package/templates/nextblock-template/docker/kong/kong.yml +112 -112
  154. package/templates/nextblock-template/docs/01-PROJECT-OVERVIEW.md +94 -94
  155. package/templates/nextblock-template/docs/02-ECOMMERCE-CAPABILITIES.md +364 -364
  156. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +202 -202
  157. package/templates/nextblock-template/docs/04-DATABASE-AND-AUTH.md +246 -246
  158. package/templates/nextblock-template/docs/06-CLI-AND-SCAFFOLDING.md +176 -176
  159. package/templates/nextblock-template/docs/07-BLOCK-SDK-AND-EXTENSIBILITY.md +146 -146
  160. package/templates/nextblock-template/docs/10-CUSTOM-BLOCKS.md +222 -222
  161. package/templates/nextblock-template/docs/11-SELF-HOSTED-DOCKER.md +173 -173
  162. package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +170 -170
  163. package/templates/nextblock-template/docs/13-STAYING-UP-TO-DATE.md +151 -151
  164. package/templates/nextblock-template/docs/README.md +39 -39
  165. package/templates/nextblock-template/hooks/use-hotkeys.ts +21 -21
  166. package/templates/nextblock-template/hooks/useGlobalSearch.ts +101 -101
  167. package/templates/nextblock-template/index.d.ts +7 -7
  168. package/templates/nextblock-template/lib/app-secrets.ts +39 -39
  169. package/templates/nextblock-template/lib/auth/cookies.ts +47 -47
  170. package/templates/nextblock-template/lib/auth/crypto.ts +45 -45
  171. package/templates/nextblock-template/lib/auth/trustedDevices.ts +92 -92
  172. package/templates/nextblock-template/lib/auth-redirects.ts +46 -46
  173. package/templates/nextblock-template/lib/blocks/README.md +13 -13
  174. package/templates/nextblock-template/lib/botProtection/verify.ts +134 -134
  175. package/templates/nextblock-template/lib/cms-transfer/server.ts +2243 -2243
  176. package/templates/nextblock-template/lib/cms-transfer/types.ts +145 -145
  177. package/templates/nextblock-template/lib/custom-block-definitions.ts +87 -87
  178. package/templates/nextblock-template/lib/custom-block-r2-upload-shared.ts +178 -178
  179. package/templates/nextblock-template/lib/custom-block-r2-upload.test.ts +140 -140
  180. package/templates/nextblock-template/lib/custom-block-r2-upload.ts +88 -88
  181. package/templates/nextblock-template/lib/custom-block-relations.test.ts +227 -227
  182. package/templates/nextblock-template/lib/custom-block-relations.ts +279 -279
  183. package/templates/nextblock-template/lib/custom-block-safelist.ts +14 -14
  184. package/templates/nextblock-template/lib/editor/dynamic-extension-core.test.ts +172 -172
  185. package/templates/nextblock-template/lib/editor/dynamic-extension-core.ts +213 -213
  186. package/templates/nextblock-template/lib/editor/dynamic-extension-loader.ts +22 -22
  187. package/templates/nextblock-template/lib/editor/dynamic-extensions.tsx +193 -193
  188. package/templates/nextblock-template/lib/email/branding-format.test.ts +133 -133
  189. package/templates/nextblock-template/lib/email/branding-format.ts +123 -123
  190. package/templates/nextblock-template/lib/email/branding.ts +76 -76
  191. package/templates/nextblock-template/lib/full-backup/manifest.test.ts +121 -121
  192. package/templates/nextblock-template/lib/full-backup/manifest.ts +206 -206
  193. package/templates/nextblock-template/lib/full-backup/server.ts +743 -743
  194. package/templates/nextblock-template/lib/logos/active-logo.ts +53 -53
  195. package/templates/nextblock-template/lib/media/resolveMediaUrl.ts +54 -54
  196. package/templates/nextblock-template/lib/media/youtube.ts +99 -99
  197. package/templates/nextblock-template/lib/onboarding/actions.ts +31 -31
  198. package/templates/nextblock-template/lib/onboarding/status.ts +222 -222
  199. package/templates/nextblock-template/lib/posts/readTime.ts +60 -60
  200. package/templates/nextblock-template/lib/privacy/consent-client.ts +57 -57
  201. package/templates/nextblock-template/lib/privacy/contact-emails.ts +64 -64
  202. package/templates/nextblock-template/lib/privacy/settings.ts +115 -115
  203. package/templates/nextblock-template/lib/privacy/types.ts +69 -69
  204. package/templates/nextblock-template/lib/promotions/server.test.ts +74 -74
  205. package/templates/nextblock-template/lib/promotions/server.ts +741 -741
  206. package/templates/nextblock-template/lib/resolve-block-relations.test.ts +142 -142
  207. package/templates/nextblock-template/lib/resolve-block-relations.ts +255 -255
  208. package/templates/nextblock-template/lib/search/types.ts +27 -27
  209. package/templates/nextblock-template/lib/setup/actions.ts +460 -460
  210. package/templates/nextblock-template/lib/setup/env-status.ts +125 -125
  211. package/templates/nextblock-template/lib/setup/env-write.ts +111 -111
  212. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +87 -87
  213. package/templates/nextblock-template/lib/setup/provisioning.ts +59 -59
  214. package/templates/nextblock-template/lib/setup/schema-apply.ts +408 -408
  215. package/templates/nextblock-template/lib/setup/system-config.ts +105 -105
  216. package/templates/nextblock-template/lib/setup/types.ts +18 -18
  217. package/templates/nextblock-template/lib/site-url.ts +48 -48
  218. package/templates/nextblock-template/lib/storage/provider.ts +66 -66
  219. package/templates/nextblock-template/lib/storage/supabase-storage.ts +103 -103
  220. package/templates/nextblock-template/lib/updates/check-upstream.ts +441 -441
  221. package/templates/nextblock-template/lib/updates/github-device.ts +206 -206
  222. package/templates/nextblock-template/lib/updates/repo-identity.ts +56 -56
  223. package/templates/nextblock-template/next-env.d.ts +1 -0
  224. package/templates/nextblock-template/package.json +6 -6
  225. package/templates/nextblock-template/postcss.config.js +6 -6
  226. package/templates/nextblock-template/scripts/backup.js +115 -115
  227. package/templates/nextblock-template/scripts/docker-setup.mjs +310 -310
  228. package/templates/nextblock-template/scripts/restore.js +385 -385
  229. package/templates/nextblock-template/scripts/verify-cortex-ai-build-widget.tsx +98 -98
  230. package/templates/nextblock-template/scripts/verify-cortex-ai-generate-blocks.ts +62 -62
  231. package/templates/nextblock-template/scripts/verify-cortex-ai-global-tools.ts +537 -537
  232. package/templates/nextblock-template/scripts/verify-cortex-ai-routing.ts +58 -58
  233. package/templates/nextblock-template/scripts/verify-custom-block-definitions.ts +188 -188
  234. package/templates/nextblock-template/scripts/verify-dynamic-custom-block-extensions.ts +123 -123
  235. package/templates/nextblock-template/scripts/verify-dynamic-layout-engine.tsx +133 -133
  236. package/templates/nextblock-template/scripts/verify-milestone-2-custom-blocks.ts +65 -65
  237. package/templates/nextblock-template/tailwind.config.js +25 -25
  238. package/templates/nextblock-template/tools/build-migrate.mjs +209 -209
  239. package/templates/nextblock-template/tools/configure-supabase-auth.js +282 -282
  240. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
  241. package/templates/nextblock-template/types/jsdom.d.ts +6 -6
  242. package/tsconfig.base.json +3 -3
@@ -1,678 +1,678 @@
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
- export interface SupabaseEnvDetected {
39
- NEXT_PUBLIC_SUPABASE_URL: boolean;
40
- SUPABASE_URL: boolean;
41
- NEXT_PUBLIC_SUPABASE_ANON_KEY: boolean;
42
- SUPABASE_ANON_KEY: boolean;
43
- SUPABASE_SERVICE_ROLE_KEY: boolean;
44
- POSTGRES_URL: boolean;
45
- }
46
-
47
- interface Props {
48
- channel: DeployChannel;
49
- configured: boolean;
50
- writable: boolean;
51
- siteUrl: string;
52
- storagePrefill: StoragePrefill;
53
- /** Which Supabase env vars the running deployment can actually see (read-only channels). */
54
- supabaseEnvDetected: SupabaseEnvDetected;
55
- }
56
-
57
- // Email (SMTP), bot protection, and sign-up policy are no longer collected here — they
58
- // moved to the CMS (Settings → Configuration) and are nudged from the dashboard onboarding
59
- // checklist. A fresh install only needs the database connection, media storage, and the
60
- // first administrator account.
61
- type StepId = 'connection' | 'storage' | 'admin';
62
-
63
- const STEP_TITLES: Record<StepId, string> = {
64
- connection: 'Database connection',
65
- storage: 'Media storage',
66
- admin: 'Administrator account',
67
- };
68
-
69
- const CHANNEL_LABEL: Record<DeployChannel, string> = {
70
- docker: 'Self-hosted Docker',
71
- vercel: 'Vercel',
72
- local: 'Local development',
73
- };
74
-
75
- type Msg = { ok: string } | { err: string } | null;
76
-
77
- export default function SetupWizard({
78
- channel,
79
- configured,
80
- writable,
81
- siteUrl,
82
- storagePrefill,
83
- supabaseEnvDetected,
84
- }: Props) {
85
- const [isPending, startTransition] = useTransition();
86
- const [message, setMessage] = useState<Msg>(null);
87
- const [phase, setPhase] = useState<'form' | 'working' | 'done'>('form');
88
-
89
- // Connection (Profile B / local only).
90
- const [conn, setConn] = useState({
91
- supabaseUrl: '',
92
- anonKey: '',
93
- serviceRoleKey: '',
94
- postgresUrl: '',
95
- accessToken: '',
96
- siteUrl,
97
- });
98
- const [connectionDone, setConnectionDone] = useState(configured);
99
- // "Start from a clean database" — only offered/honored on a local fresh install.
100
- const [resetFirst, setResetFirst] = useState(true);
101
-
102
- // Storage / admin.
103
- const [storage, setStorage] = useState(storagePrefill);
104
- const [admin, setAdmin] = useState({ email: '', password: '', fullName: '' });
105
-
106
- const steps = useMemo<StepId[]>(() => {
107
- const list: StepId[] = [];
108
- if (!configured) {
109
- list.push('connection');
110
- }
111
- // Skip the storage step when there's nothing for the user to configure: one-click Vercel
112
- // deploys use the connected Supabase project with zero keys (native Supabase Storage), and
113
- // the Docker stack ships MinIO already wired up by docker-setup (a read-only prefill).
114
- if (channel !== 'vercel' && !storagePrefill.readOnly) {
115
- list.push('storage');
116
- }
117
- list.push('admin');
118
- return list;
119
- }, [configured, channel, storagePrefill.readOnly]);
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
- // Both must hold the bucket's public read URL: image src is built from
186
- // NEXT_PUBLIC_R2_BASE_URL, while next.config remotePatterns + CSP read
187
- // NEXT_PUBLIC_R2_PUBLIC_URL. The wizard collects one URL and writes it to both
188
- // (baseUrl only differs if a channel prefilled a separate custom domain).
189
- put('NEXT_PUBLIC_R2_PUBLIC_URL', storage.publicUrl);
190
- put('NEXT_PUBLIC_R2_BASE_URL', storage.baseUrl || storage.publicUrl);
191
- }
192
-
193
- setMessage(null);
194
- setPhase('working');
195
- startTransition(async () => {
196
- const result = await completeSetup({
197
- admin,
198
- envValues,
199
- resetFirst: resetFirst && writable,
200
- });
201
-
202
- if (!result.ok) {
203
- setErr(result.error ?? 'Setup failed.');
204
- setPhase('form');
205
- return;
206
- }
207
-
208
- // Establish the session via the canonical sign-in path (reliable cookie), which
209
- // redirects into the CMS. With the runtime public-env injection the client works
210
- // without a dev-server restart.
211
- const signInData = new FormData();
212
- signInData.append('email', admin.email.trim());
213
- signInData.append('password', admin.password);
214
- await signInAction(signInData);
215
-
216
- // signInAction redirects on success (and on failure, to /sign-in with a message),
217
- // so this only runs in the unlikely case it returned without navigating.
218
- setPhase('done');
219
- });
220
- };
221
-
222
- // --- Render ------------------------------------------------------------------
223
-
224
- if (phase === 'working') {
225
- return (
226
- <div className="space-y-6">
227
- <SetupProgress willReset={resetFirst && writable} />
228
- </div>
229
- );
230
- }
231
-
232
- if (phase === 'done') {
233
- return (
234
- <div className="space-y-6">
235
- <SetupDone />
236
- </div>
237
- );
238
- }
239
-
240
- const alert =
241
- message &&
242
- ('ok' in message ? (
243
- <Alert variant="success" className="py-2 px-4">
244
- <AlertDescription>{message.ok}</AlertDescription>
245
- </Alert>
246
- ) : (
247
- <Alert variant="destructive" className="py-2 px-4">
248
- <AlertDescription>{message.err}</AlertDescription>
249
- </Alert>
250
- ));
251
-
252
- return (
253
- <div className="space-y-6">
254
- <div className="space-y-2 text-center">
255
- <h1 className="text-2xl font-semibold">Welcome to NextBlock</h1>
256
- <div className="text-sm text-muted-foreground">
257
- Let&rsquo;s get your CMS running. Detected environment:{' '}
258
- <Badge variant="secondary">{CHANNEL_LABEL[channel]}</Badge>
259
- </div>
260
- </div>
261
-
262
- <Stepper steps={steps} stepIndex={stepIndex} />
263
-
264
- <Card>
265
- <CardHeader>
266
- <CardTitle>{STEP_TITLES[current]}</CardTitle>
267
- <CardDescription>{stepDescription(current, channel)}</CardDescription>
268
- </CardHeader>
269
- <CardContent className="space-y-5">
270
- {alert}
271
-
272
- {current === 'connection' && (
273
- <div className="space-y-4">
274
- <Field label="Supabase URL" htmlFor="supabaseUrl">
275
- <Input
276
- id="supabaseUrl"
277
- placeholder="https://YOUR-PROJECT.supabase.co"
278
- value={conn.supabaseUrl}
279
- onChange={(e) => setConn({ ...conn, supabaseUrl: e.target.value })}
280
- />
281
- </Field>
282
- <Field label="Anon (publishable) key" htmlFor="anonKey">
283
- <Input
284
- id="anonKey"
285
- value={conn.anonKey}
286
- onChange={(e) => setConn({ ...conn, anonKey: e.target.value })}
287
- />
288
- </Field>
289
- <Field label="Service-role (secret) key" htmlFor="serviceRoleKey">
290
- <Input
291
- id="serviceRoleKey"
292
- type="password"
293
- value={conn.serviceRoleKey}
294
- onChange={(e) => setConn({ ...conn, serviceRoleKey: e.target.value })}
295
- />
296
- </Field>
297
- <Field label="Supabase access token" htmlFor="accessToken">
298
- <Input
299
- id="accessToken"
300
- type="password"
301
- placeholder="sbp_… (Account → Access Tokens)"
302
- value={conn.accessToken}
303
- onChange={(e) => setConn({ ...conn, accessToken: e.target.value })}
304
- />
305
- <p className="text-xs text-muted-foreground">
306
- Recommended — lets the wizard apply the database schema over HTTPS (works on any
307
- network, no database host to reach).
308
- </p>
309
- </Field>
310
- <Field label="Postgres connection string (optional)" htmlFor="postgresUrl">
311
- <Input
312
- id="postgresUrl"
313
- placeholder="postgresql://postgres.<ref>:[password]@aws-0-<region>.pooler.supabase.com:5432/postgres"
314
- value={conn.postgresUrl}
315
- onChange={(e) => setConn({ ...conn, postgresUrl: e.target.value })}
316
- />
317
- <p className="text-xs text-muted-foreground">
318
- Fallback used only if no access token is given. Use the <strong>Session pooler</strong>{' '}
319
- string (Supabase → Connect → Session pooler); the &ldquo;direct&rdquo;{' '}
320
- <code>db.&lt;ref&gt;.supabase.co</code> host fails on IPv4-only networks.
321
- </p>
322
- </Field>
323
- <Field label="Public site URL (optional)" htmlFor="siteUrl">
324
- <Input
325
- id="siteUrl"
326
- placeholder="http://localhost:4200"
327
- value={conn.siteUrl}
328
- onChange={(e) => setConn({ ...conn, siteUrl: e.target.value })}
329
- />
330
- </Field>
331
- {!writable && (
332
- <div className="space-y-3 rounded-md border p-4">
333
- <p className="text-sm font-medium">
334
- On {CHANNEL_LABEL[channel]} you don&apos;t fill this in — the database is
335
- connected through your platform&apos;s environment variables (e.g. Vercel&apos;s
336
- Supabase integration).
337
- </p>
338
- <div className="text-xs">
339
- <p className="mb-1 text-muted-foreground">
340
- Supabase variables this deployment can currently see:
341
- </p>
342
- <ul className="space-y-0.5 font-mono">
343
- {(
344
- [
345
- 'NEXT_PUBLIC_SUPABASE_URL',
346
- 'SUPABASE_URL',
347
- 'NEXT_PUBLIC_SUPABASE_ANON_KEY',
348
- 'SUPABASE_ANON_KEY',
349
- 'SUPABASE_SERVICE_ROLE_KEY',
350
- 'POSTGRES_URL',
351
- ] as const
352
- ).map((k) => (
353
- <li key={k}>
354
- {supabaseEnvDetected[k] ? '✅' : '❌'} {k}
355
- </li>
356
- ))}
357
- </ul>
358
- </div>
359
- <Alert className="py-2 px-4">
360
- <AlertDescription className="text-xs">
361
- {supabaseEnvDetected.NEXT_PUBLIC_SUPABASE_URL ||
362
- supabaseEnvDetected.SUPABASE_URL
363
- ? 'Keys detected — reload this page and the database step will be skipped.'
364
- : 'No Supabase keys are visible to this deployment yet. If you just created the database via the Vercel integration, the keys were added AFTER this build — open Vercel → Deployments → ⋯ → Redeploy once, then reload. Env vars only bind on a new deployment.'}
365
- </AlertDescription>
366
- </Alert>
367
- </div>
368
- )}
369
- </div>
370
- )}
371
-
372
- {current === 'storage' && (
373
- <StorageStep storage={storage} setStorage={setStorage} channel={channel} />
374
- )}
375
-
376
- {current === 'admin' && (
377
- <div className="space-y-4">
378
- <Field label="Full name" htmlFor="adminName">
379
- <Input
380
- id="adminName"
381
- value={admin.fullName}
382
- onChange={(e) => setAdmin({ ...admin, fullName: e.target.value })}
383
- />
384
- </Field>
385
- <Field label="Email" htmlFor="adminEmail">
386
- <Input
387
- id="adminEmail"
388
- type="email"
389
- value={admin.email}
390
- onChange={(e) => setAdmin({ ...admin, email: e.target.value })}
391
- />
392
- </Field>
393
- <Field label="Password" htmlFor="adminPassword">
394
- <Input
395
- id="adminPassword"
396
- type="password"
397
- value={admin.password}
398
- onChange={(e) => setAdmin({ ...admin, password: e.target.value })}
399
- />
400
- </Field>
401
- <p className="text-xs text-muted-foreground">
402
- This first account becomes the site administrator, created already-confirmed (no
403
- verification email needed). Finishing also applies the database schema and saved
404
- settings, so it can take up to a minute.
405
- </p>
406
- <Alert className="py-2 px-4">
407
- <AlertDescription className="text-xs">
408
- Next, your dashboard will guide you through finishing setup — branding, copyright,
409
- email (SMTP), payment providers, and bot protection are all configured there, no
410
- environment variables required.
411
- </AlertDescription>
412
- </Alert>
413
-
414
- {writable && (
415
- <label className="flex items-start gap-3 rounded-lg border p-3">
416
- <Checkbox
417
- checked={resetFirst}
418
- onCheckedChange={(c) => setResetFirst(c === true)}
419
- className="mt-1"
420
- />
421
- <span className="text-sm">
422
- <span className="font-medium">Start from a clean database</span>
423
- <span className="block text-xs text-muted-foreground">
424
- Recommended for a fresh install. Wipes any existing tables, migration history,
425
- and users in this Supabase project before installing. Uncheck if this database
426
- already has data you want to keep.
427
- </span>
428
- </span>
429
- </label>
430
- )}
431
- </div>
432
- )}
433
-
434
- <Separator />
435
-
436
- <div className="flex items-center justify-between">
437
- <Button variant="ghost" onClick={goBack} disabled={isPending || stepIndex === 0}>
438
- Back
439
- </Button>
440
-
441
- {current === 'connection' ? (
442
- <Button onClick={handleSaveConnection} disabled={isPending || !writable}>
443
- {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
444
- Save &amp; verify
445
- </Button>
446
- ) : isLast ? (
447
- <Button onClick={handleFinish} disabled={isPending}>
448
- {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
449
- Finish setup
450
- </Button>
451
- ) : (
452
- <Button onClick={goNext} disabled={!connectionDone && !configured}>
453
- Next
454
- </Button>
455
- )}
456
- </div>
457
- </CardContent>
458
- </Card>
459
- </div>
460
- );
461
- }
462
-
463
- function stepDescription(step: StepId, channel: DeployChannel): string {
464
- switch (step) {
465
- case 'connection':
466
- return 'Connect this instance to your Supabase project.';
467
- case 'storage':
468
- return channel === 'docker'
469
- ? 'Your Docker stack uses MinIO for media storage — already wired up.'
470
- : channel === 'vercel'
471
- ? 'Using Supabase Storage (S3-compatible) for media.'
472
- : 'Bring your own Cloudflare R2 bucket for media storage.';
473
- case 'admin':
474
- return 'Create the first administrator account — the last step. Email, payments, branding, and the rest are configured from your dashboard.';
475
- default:
476
- return '';
477
- }
478
- }
479
-
480
- const PROGRESS_MESSAGES = [
481
- 'Laying the foundation blocks…',
482
- 'Seeding the first blocks…',
483
- 'Stacking a few more blocks…',
484
- 'Teaching the blocks to speak (translations)…',
485
- 'Waiting on some stubborn blocks…',
486
- 'Polishing the blocks until they shine…',
487
- 'Almost there — slotting in the last blocks…',
488
- ];
489
-
490
- function SetupProgress({ willReset }: { willReset: boolean }) {
491
- const messages = willReset
492
- ? ['Wiping the old blocks away…', ...PROGRESS_MESSAGES]
493
- : PROGRESS_MESSAGES;
494
- const [pct, setPct] = useState(8);
495
- const [msgIndex, setMsgIndex] = useState(0);
496
-
497
- useEffect(() => {
498
- // Indeterminate work (one server action) shown as a friendly creeping bar that eases
499
- // toward ~92% and a rotating set of block-themed messages.
500
- const progress = setInterval(() => {
501
- setPct((value) => (value >= 92 ? 92 : value + Math.max(1, Math.round((96 - value) / 14))));
502
- }, 700);
503
- const cycle = setInterval(() => {
504
- setMsgIndex((index) => (index + 1) % messages.length);
505
- }, 2200);
506
- return () => {
507
- clearInterval(progress);
508
- clearInterval(cycle);
509
- };
510
- }, [messages.length]);
511
-
512
- return (
513
- <Card>
514
- <CardHeader>
515
- <CardTitle>Building your NextBlock…</CardTitle>
516
- <CardDescription>
517
- {willReset ? 'Resetting the database, then applying' : 'Applying'} the schema, seeding
518
- content, and creating your account. This can take a minute — hang tight.
519
- </CardDescription>
520
- </CardHeader>
521
- <CardContent className="space-y-4">
522
- <div className="h-2 w-full overflow-hidden rounded-full bg-muted">
523
- <div
524
- className="h-full rounded-full bg-primary transition-all duration-700 ease-out"
525
- style={{ width: `${pct}%` }}
526
- />
527
- </div>
528
- <p className="text-sm text-muted-foreground">{messages[msgIndex]}</p>
529
- </CardContent>
530
- </Card>
531
- );
532
- }
533
-
534
- function SetupDone() {
535
- return (
536
- <Card>
537
- <CardHeader>
538
- <CardTitle>🎉 Setup complete!</CardTitle>
539
- <CardDescription>
540
- Your administrator account is ready and the database is seeded.
541
- </CardDescription>
542
- </CardHeader>
543
- <CardContent>
544
- <Button onClick={() => (window.location.href = '/cms/dashboard')}>Enter your CMS</Button>
545
- </CardContent>
546
- </Card>
547
- );
548
- }
549
-
550
- function Stepper({
551
- steps,
552
- stepIndex,
553
- }: {
554
- steps: StepId[];
555
- stepIndex: number;
556
- }) {
557
- return (
558
- <ol className="flex flex-wrap items-center justify-center gap-2 text-xs">
559
- {steps.map((s, i) => (
560
- <li
561
- key={s}
562
- className={`flex items-center gap-2 rounded-full border px-3 py-1 ${
563
- i === stepIndex
564
- ? 'border-primary text-primary'
565
- : i < stepIndex
566
- ? 'border-muted text-muted-foreground'
567
- : 'border-muted text-muted-foreground/60'
568
- }`}
569
- >
570
- <span className="font-medium">{i + 1}</span>
571
- <span>{STEP_TITLES[s]}</span>
572
- </li>
573
- ))}
574
- </ol>
575
- );
576
- }
577
-
578
- function StorageStep({
579
- storage,
580
- setStorage,
581
- channel,
582
- }: {
583
- storage: StoragePrefill;
584
- setStorage: (s: StoragePrefill) => void;
585
- channel: DeployChannel;
586
- }) {
587
- if (channel === 'docker') {
588
- return (
589
- <div className="space-y-3 text-sm">
590
- <Alert variant="success" className="py-2 px-4">
591
- <AlertDescription>
592
- MinIO is already configured by the Docker setup. Nothing to do here.
593
- </AlertDescription>
594
- </Alert>
595
- <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs text-muted-foreground">
596
- <dt>Endpoint</dt>
597
- <dd className="font-mono">{storage.endpoint}</dd>
598
- <dt>Bucket</dt>
599
- <dd className="font-mono">{storage.bucket}</dd>
600
- <dt>Public URL</dt>
601
- <dd className="font-mono">{storage.publicUrl}</dd>
602
- </dl>
603
- </div>
604
- );
605
- }
606
-
607
- return (
608
- <div className="space-y-4">
609
- {channel === 'vercel' && (
610
- <p className="text-xs text-muted-foreground">
611
- Pre-filled for Supabase Storage. Create an S3 access key in your Supabase project
612
- (Storage → S3 connection) and set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY in your Vercel
613
- environment.
614
- </p>
615
- )}
616
- <div className="grid gap-4 sm:grid-cols-2">
617
- <Field label="Account / provider id" htmlFor="r2Account">
618
- <Input
619
- id="r2Account"
620
- value={storage.accountId}
621
- onChange={(e) => setStorage({ ...storage, accountId: e.target.value })}
622
- />
623
- </Field>
624
- <Field label="Bucket" htmlFor="r2Bucket">
625
- <Input
626
- id="r2Bucket"
627
- value={storage.bucket}
628
- onChange={(e) => setStorage({ ...storage, bucket: e.target.value })}
629
- />
630
- </Field>
631
- <Field label="Access key id" htmlFor="r2Access">
632
- <Input
633
- id="r2Access"
634
- value={storage.accessKeyId}
635
- onChange={(e) => setStorage({ ...storage, accessKeyId: e.target.value })}
636
- />
637
- </Field>
638
- <Field label="Secret access key" htmlFor="r2Secret">
639
- <Input
640
- id="r2Secret"
641
- type="password"
642
- value={storage.secretAccessKey}
643
- onChange={(e) => setStorage({ ...storage, secretAccessKey: e.target.value })}
644
- />
645
- </Field>
646
- </div>
647
- <Field label="Public bucket URL" htmlFor="r2Public">
648
- <Input
649
- id="r2Public"
650
- placeholder="https://pub-xxxx.r2.dev"
651
- value={storage.publicUrl}
652
- onChange={(e) => setStorage({ ...storage, publicUrl: e.target.value })}
653
- />
654
- <p className="mt-1 text-xs text-muted-foreground">
655
- Your bucket&apos;s public URL (Cloudflare R2 → your bucket → Public Development URL)
656
- or a custom domain. Used to serve all media on your site.
657
- </p>
658
- </Field>
659
- </div>
660
- );
661
- }
662
-
663
- function Field({
664
- label,
665
- htmlFor,
666
- children,
667
- }: {
668
- label: string;
669
- htmlFor: string;
670
- children: React.ReactNode;
671
- }) {
672
- return (
673
- <div className="space-y-1.5">
674
- <Label htmlFor={htmlFor}>{label}</Label>
675
- {children}
676
- </div>
677
- );
678
- }
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
+ export interface SupabaseEnvDetected {
39
+ NEXT_PUBLIC_SUPABASE_URL: boolean;
40
+ SUPABASE_URL: boolean;
41
+ NEXT_PUBLIC_SUPABASE_ANON_KEY: boolean;
42
+ SUPABASE_ANON_KEY: boolean;
43
+ SUPABASE_SERVICE_ROLE_KEY: boolean;
44
+ POSTGRES_URL: boolean;
45
+ }
46
+
47
+ interface Props {
48
+ channel: DeployChannel;
49
+ configured: boolean;
50
+ writable: boolean;
51
+ siteUrl: string;
52
+ storagePrefill: StoragePrefill;
53
+ /** Which Supabase env vars the running deployment can actually see (read-only channels). */
54
+ supabaseEnvDetected: SupabaseEnvDetected;
55
+ }
56
+
57
+ // Email (SMTP), bot protection, and sign-up policy are no longer collected here — they
58
+ // moved to the CMS (Settings → Configuration) and are nudged from the dashboard onboarding
59
+ // checklist. A fresh install only needs the database connection, media storage, and the
60
+ // first administrator account.
61
+ type StepId = 'connection' | 'storage' | 'admin';
62
+
63
+ const STEP_TITLES: Record<StepId, string> = {
64
+ connection: 'Database connection',
65
+ storage: 'Media storage',
66
+ admin: 'Administrator account',
67
+ };
68
+
69
+ const CHANNEL_LABEL: Record<DeployChannel, string> = {
70
+ docker: 'Self-hosted Docker',
71
+ vercel: 'Vercel',
72
+ local: 'Local development',
73
+ };
74
+
75
+ type Msg = { ok: string } | { err: string } | null;
76
+
77
+ export default function SetupWizard({
78
+ channel,
79
+ configured,
80
+ writable,
81
+ siteUrl,
82
+ storagePrefill,
83
+ supabaseEnvDetected,
84
+ }: Props) {
85
+ const [isPending, startTransition] = useTransition();
86
+ const [message, setMessage] = useState<Msg>(null);
87
+ const [phase, setPhase] = useState<'form' | 'working' | 'done'>('form');
88
+
89
+ // Connection (Profile B / local only).
90
+ const [conn, setConn] = useState({
91
+ supabaseUrl: '',
92
+ anonKey: '',
93
+ serviceRoleKey: '',
94
+ postgresUrl: '',
95
+ accessToken: '',
96
+ siteUrl,
97
+ });
98
+ const [connectionDone, setConnectionDone] = useState(configured);
99
+ // "Start from a clean database" — only offered/honored on a local fresh install.
100
+ const [resetFirst, setResetFirst] = useState(true);
101
+
102
+ // Storage / admin.
103
+ const [storage, setStorage] = useState(storagePrefill);
104
+ const [admin, setAdmin] = useState({ email: '', password: '', fullName: '' });
105
+
106
+ const steps = useMemo<StepId[]>(() => {
107
+ const list: StepId[] = [];
108
+ if (!configured) {
109
+ list.push('connection');
110
+ }
111
+ // Skip the storage step when there's nothing for the user to configure: one-click Vercel
112
+ // deploys use the connected Supabase project with zero keys (native Supabase Storage), and
113
+ // the Docker stack ships MinIO already wired up by docker-setup (a read-only prefill).
114
+ if (channel !== 'vercel' && !storagePrefill.readOnly) {
115
+ list.push('storage');
116
+ }
117
+ list.push('admin');
118
+ return list;
119
+ }, [configured, channel, storagePrefill.readOnly]);
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
+ // Both must hold the bucket's public read URL: image src is built from
186
+ // NEXT_PUBLIC_R2_BASE_URL, while next.config remotePatterns + CSP read
187
+ // NEXT_PUBLIC_R2_PUBLIC_URL. The wizard collects one URL and writes it to both
188
+ // (baseUrl only differs if a channel prefilled a separate custom domain).
189
+ put('NEXT_PUBLIC_R2_PUBLIC_URL', storage.publicUrl);
190
+ put('NEXT_PUBLIC_R2_BASE_URL', storage.baseUrl || storage.publicUrl);
191
+ }
192
+
193
+ setMessage(null);
194
+ setPhase('working');
195
+ startTransition(async () => {
196
+ const result = await completeSetup({
197
+ admin,
198
+ envValues,
199
+ resetFirst: resetFirst && writable,
200
+ });
201
+
202
+ if (!result.ok) {
203
+ setErr(result.error ?? 'Setup failed.');
204
+ setPhase('form');
205
+ return;
206
+ }
207
+
208
+ // Establish the session via the canonical sign-in path (reliable cookie), which
209
+ // redirects into the CMS. With the runtime public-env injection the client works
210
+ // without a dev-server restart.
211
+ const signInData = new FormData();
212
+ signInData.append('email', admin.email.trim());
213
+ signInData.append('password', admin.password);
214
+ await signInAction(signInData);
215
+
216
+ // signInAction redirects on success (and on failure, to /sign-in with a message),
217
+ // so this only runs in the unlikely case it returned without navigating.
218
+ setPhase('done');
219
+ });
220
+ };
221
+
222
+ // --- Render ------------------------------------------------------------------
223
+
224
+ if (phase === 'working') {
225
+ return (
226
+ <div className="space-y-6">
227
+ <SetupProgress willReset={resetFirst && writable} />
228
+ </div>
229
+ );
230
+ }
231
+
232
+ if (phase === 'done') {
233
+ return (
234
+ <div className="space-y-6">
235
+ <SetupDone />
236
+ </div>
237
+ );
238
+ }
239
+
240
+ const alert =
241
+ message &&
242
+ ('ok' in message ? (
243
+ <Alert variant="success" className="py-2 px-4">
244
+ <AlertDescription>{message.ok}</AlertDescription>
245
+ </Alert>
246
+ ) : (
247
+ <Alert variant="destructive" className="py-2 px-4">
248
+ <AlertDescription>{message.err}</AlertDescription>
249
+ </Alert>
250
+ ));
251
+
252
+ return (
253
+ <div className="space-y-6">
254
+ <div className="space-y-2 text-center">
255
+ <h1 className="text-2xl font-semibold">Welcome to NextBlock</h1>
256
+ <div className="text-sm text-muted-foreground">
257
+ Let&rsquo;s get your CMS running. Detected environment:{' '}
258
+ <Badge variant="secondary">{CHANNEL_LABEL[channel]}</Badge>
259
+ </div>
260
+ </div>
261
+
262
+ <Stepper steps={steps} stepIndex={stepIndex} />
263
+
264
+ <Card>
265
+ <CardHeader>
266
+ <CardTitle>{STEP_TITLES[current]}</CardTitle>
267
+ <CardDescription>{stepDescription(current, channel)}</CardDescription>
268
+ </CardHeader>
269
+ <CardContent className="space-y-5">
270
+ {alert}
271
+
272
+ {current === 'connection' && (
273
+ <div className="space-y-4">
274
+ <Field label="Supabase URL" htmlFor="supabaseUrl">
275
+ <Input
276
+ id="supabaseUrl"
277
+ placeholder="https://YOUR-PROJECT.supabase.co"
278
+ value={conn.supabaseUrl}
279
+ onChange={(e) => setConn({ ...conn, supabaseUrl: e.target.value })}
280
+ />
281
+ </Field>
282
+ <Field label="Anon (publishable) key" htmlFor="anonKey">
283
+ <Input
284
+ id="anonKey"
285
+ value={conn.anonKey}
286
+ onChange={(e) => setConn({ ...conn, anonKey: e.target.value })}
287
+ />
288
+ </Field>
289
+ <Field label="Service-role (secret) key" htmlFor="serviceRoleKey">
290
+ <Input
291
+ id="serviceRoleKey"
292
+ type="password"
293
+ value={conn.serviceRoleKey}
294
+ onChange={(e) => setConn({ ...conn, serviceRoleKey: e.target.value })}
295
+ />
296
+ </Field>
297
+ <Field label="Supabase access token" htmlFor="accessToken">
298
+ <Input
299
+ id="accessToken"
300
+ type="password"
301
+ placeholder="sbp_… (Account → Access Tokens)"
302
+ value={conn.accessToken}
303
+ onChange={(e) => setConn({ ...conn, accessToken: e.target.value })}
304
+ />
305
+ <p className="text-xs text-muted-foreground">
306
+ Recommended — lets the wizard apply the database schema over HTTPS (works on any
307
+ network, no database host to reach).
308
+ </p>
309
+ </Field>
310
+ <Field label="Postgres connection string (optional)" htmlFor="postgresUrl">
311
+ <Input
312
+ id="postgresUrl"
313
+ placeholder="postgresql://postgres.<ref>:[password]@aws-0-<region>.pooler.supabase.com:5432/postgres"
314
+ value={conn.postgresUrl}
315
+ onChange={(e) => setConn({ ...conn, postgresUrl: e.target.value })}
316
+ />
317
+ <p className="text-xs text-muted-foreground">
318
+ Fallback used only if no access token is given. Use the <strong>Session pooler</strong>{' '}
319
+ string (Supabase → Connect → Session pooler); the &ldquo;direct&rdquo;{' '}
320
+ <code>db.&lt;ref&gt;.supabase.co</code> host fails on IPv4-only networks.
321
+ </p>
322
+ </Field>
323
+ <Field label="Public site URL (optional)" htmlFor="siteUrl">
324
+ <Input
325
+ id="siteUrl"
326
+ placeholder="http://localhost:4200"
327
+ value={conn.siteUrl}
328
+ onChange={(e) => setConn({ ...conn, siteUrl: e.target.value })}
329
+ />
330
+ </Field>
331
+ {!writable && (
332
+ <div className="space-y-3 rounded-md border p-4">
333
+ <p className="text-sm font-medium">
334
+ On {CHANNEL_LABEL[channel]} you don&apos;t fill this in — the database is
335
+ connected through your platform&apos;s environment variables (e.g. Vercel&apos;s
336
+ Supabase integration).
337
+ </p>
338
+ <div className="text-xs">
339
+ <p className="mb-1 text-muted-foreground">
340
+ Supabase variables this deployment can currently see:
341
+ </p>
342
+ <ul className="space-y-0.5 font-mono">
343
+ {(
344
+ [
345
+ 'NEXT_PUBLIC_SUPABASE_URL',
346
+ 'SUPABASE_URL',
347
+ 'NEXT_PUBLIC_SUPABASE_ANON_KEY',
348
+ 'SUPABASE_ANON_KEY',
349
+ 'SUPABASE_SERVICE_ROLE_KEY',
350
+ 'POSTGRES_URL',
351
+ ] as const
352
+ ).map((k) => (
353
+ <li key={k}>
354
+ {supabaseEnvDetected[k] ? '✅' : '❌'} {k}
355
+ </li>
356
+ ))}
357
+ </ul>
358
+ </div>
359
+ <Alert className="py-2 px-4">
360
+ <AlertDescription className="text-xs">
361
+ {supabaseEnvDetected.NEXT_PUBLIC_SUPABASE_URL ||
362
+ supabaseEnvDetected.SUPABASE_URL
363
+ ? 'Keys detected — reload this page and the database step will be skipped.'
364
+ : 'No Supabase keys are visible to this deployment yet. If you just created the database via the Vercel integration, the keys were added AFTER this build — open Vercel → Deployments → ⋯ → Redeploy once, then reload. Env vars only bind on a new deployment.'}
365
+ </AlertDescription>
366
+ </Alert>
367
+ </div>
368
+ )}
369
+ </div>
370
+ )}
371
+
372
+ {current === 'storage' && (
373
+ <StorageStep storage={storage} setStorage={setStorage} channel={channel} />
374
+ )}
375
+
376
+ {current === 'admin' && (
377
+ <div className="space-y-4">
378
+ <Field label="Full name" htmlFor="adminName">
379
+ <Input
380
+ id="adminName"
381
+ value={admin.fullName}
382
+ onChange={(e) => setAdmin({ ...admin, fullName: e.target.value })}
383
+ />
384
+ </Field>
385
+ <Field label="Email" htmlFor="adminEmail">
386
+ <Input
387
+ id="adminEmail"
388
+ type="email"
389
+ value={admin.email}
390
+ onChange={(e) => setAdmin({ ...admin, email: e.target.value })}
391
+ />
392
+ </Field>
393
+ <Field label="Password" htmlFor="adminPassword">
394
+ <Input
395
+ id="adminPassword"
396
+ type="password"
397
+ value={admin.password}
398
+ onChange={(e) => setAdmin({ ...admin, password: e.target.value })}
399
+ />
400
+ </Field>
401
+ <p className="text-xs text-muted-foreground">
402
+ This first account becomes the site administrator, created already-confirmed (no
403
+ verification email needed). Finishing also applies the database schema and saved
404
+ settings, so it can take up to a minute.
405
+ </p>
406
+ <Alert className="py-2 px-4">
407
+ <AlertDescription className="text-xs">
408
+ Next, your dashboard will guide you through finishing setup — branding, copyright,
409
+ email (SMTP), payment providers, and bot protection are all configured there, no
410
+ environment variables required.
411
+ </AlertDescription>
412
+ </Alert>
413
+
414
+ {writable && (
415
+ <label className="flex items-start gap-3 rounded-lg border p-3">
416
+ <Checkbox
417
+ checked={resetFirst}
418
+ onCheckedChange={(c) => setResetFirst(c === true)}
419
+ className="mt-1"
420
+ />
421
+ <span className="text-sm">
422
+ <span className="font-medium">Start from a clean database</span>
423
+ <span className="block text-xs text-muted-foreground">
424
+ Recommended for a fresh install. Wipes any existing tables, migration history,
425
+ and users in this Supabase project before installing. Uncheck if this database
426
+ already has data you want to keep.
427
+ </span>
428
+ </span>
429
+ </label>
430
+ )}
431
+ </div>
432
+ )}
433
+
434
+ <Separator />
435
+
436
+ <div className="flex items-center justify-between">
437
+ <Button variant="ghost" onClick={goBack} disabled={isPending || stepIndex === 0}>
438
+ Back
439
+ </Button>
440
+
441
+ {current === 'connection' ? (
442
+ <Button onClick={handleSaveConnection} disabled={isPending || !writable}>
443
+ {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
444
+ Save &amp; verify
445
+ </Button>
446
+ ) : isLast ? (
447
+ <Button onClick={handleFinish} disabled={isPending}>
448
+ {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
449
+ Finish setup
450
+ </Button>
451
+ ) : (
452
+ <Button onClick={goNext} disabled={!connectionDone && !configured}>
453
+ Next
454
+ </Button>
455
+ )}
456
+ </div>
457
+ </CardContent>
458
+ </Card>
459
+ </div>
460
+ );
461
+ }
462
+
463
+ function stepDescription(step: StepId, channel: DeployChannel): string {
464
+ switch (step) {
465
+ case 'connection':
466
+ return 'Connect this instance to your Supabase project.';
467
+ case 'storage':
468
+ return channel === 'docker'
469
+ ? 'Your Docker stack uses MinIO for media storage — already wired up.'
470
+ : channel === 'vercel'
471
+ ? 'Using Supabase Storage (S3-compatible) for media.'
472
+ : 'Bring your own Cloudflare R2 bucket for media storage.';
473
+ case 'admin':
474
+ return 'Create the first administrator account — the last step. Email, payments, branding, and the rest are configured from your dashboard.';
475
+ default:
476
+ return '';
477
+ }
478
+ }
479
+
480
+ const PROGRESS_MESSAGES = [
481
+ 'Laying the foundation blocks…',
482
+ 'Seeding the first blocks…',
483
+ 'Stacking a few more blocks…',
484
+ 'Teaching the blocks to speak (translations)…',
485
+ 'Waiting on some stubborn blocks…',
486
+ 'Polishing the blocks until they shine…',
487
+ 'Almost there — slotting in the last blocks…',
488
+ ];
489
+
490
+ function SetupProgress({ willReset }: { willReset: boolean }) {
491
+ const messages = willReset
492
+ ? ['Wiping the old blocks away…', ...PROGRESS_MESSAGES]
493
+ : PROGRESS_MESSAGES;
494
+ const [pct, setPct] = useState(8);
495
+ const [msgIndex, setMsgIndex] = useState(0);
496
+
497
+ useEffect(() => {
498
+ // Indeterminate work (one server action) shown as a friendly creeping bar that eases
499
+ // toward ~92% and a rotating set of block-themed messages.
500
+ const progress = setInterval(() => {
501
+ setPct((value) => (value >= 92 ? 92 : value + Math.max(1, Math.round((96 - value) / 14))));
502
+ }, 700);
503
+ const cycle = setInterval(() => {
504
+ setMsgIndex((index) => (index + 1) % messages.length);
505
+ }, 2200);
506
+ return () => {
507
+ clearInterval(progress);
508
+ clearInterval(cycle);
509
+ };
510
+ }, [messages.length]);
511
+
512
+ return (
513
+ <Card>
514
+ <CardHeader>
515
+ <CardTitle>Building your NextBlock…</CardTitle>
516
+ <CardDescription>
517
+ {willReset ? 'Resetting the database, then applying' : 'Applying'} the schema, seeding
518
+ content, and creating your account. This can take a minute — hang tight.
519
+ </CardDescription>
520
+ </CardHeader>
521
+ <CardContent className="space-y-4">
522
+ <div className="h-2 w-full overflow-hidden rounded-full bg-muted">
523
+ <div
524
+ className="h-full rounded-full bg-primary transition-all duration-700 ease-out"
525
+ style={{ width: `${pct}%` }}
526
+ />
527
+ </div>
528
+ <p className="text-sm text-muted-foreground">{messages[msgIndex]}</p>
529
+ </CardContent>
530
+ </Card>
531
+ );
532
+ }
533
+
534
+ function SetupDone() {
535
+ return (
536
+ <Card>
537
+ <CardHeader>
538
+ <CardTitle>🎉 Setup complete!</CardTitle>
539
+ <CardDescription>
540
+ Your administrator account is ready and the database is seeded.
541
+ </CardDescription>
542
+ </CardHeader>
543
+ <CardContent>
544
+ <Button onClick={() => (window.location.href = '/cms/dashboard')}>Enter your CMS</Button>
545
+ </CardContent>
546
+ </Card>
547
+ );
548
+ }
549
+
550
+ function Stepper({
551
+ steps,
552
+ stepIndex,
553
+ }: {
554
+ steps: StepId[];
555
+ stepIndex: number;
556
+ }) {
557
+ return (
558
+ <ol className="flex flex-wrap items-center justify-center gap-2 text-xs">
559
+ {steps.map((s, i) => (
560
+ <li
561
+ key={s}
562
+ className={`flex items-center gap-2 rounded-full border px-3 py-1 ${
563
+ i === stepIndex
564
+ ? 'border-primary text-primary'
565
+ : i < stepIndex
566
+ ? 'border-muted text-muted-foreground'
567
+ : 'border-muted text-muted-foreground/60'
568
+ }`}
569
+ >
570
+ <span className="font-medium">{i + 1}</span>
571
+ <span>{STEP_TITLES[s]}</span>
572
+ </li>
573
+ ))}
574
+ </ol>
575
+ );
576
+ }
577
+
578
+ function StorageStep({
579
+ storage,
580
+ setStorage,
581
+ channel,
582
+ }: {
583
+ storage: StoragePrefill;
584
+ setStorage: (s: StoragePrefill) => void;
585
+ channel: DeployChannel;
586
+ }) {
587
+ if (channel === 'docker') {
588
+ return (
589
+ <div className="space-y-3 text-sm">
590
+ <Alert variant="success" className="py-2 px-4">
591
+ <AlertDescription>
592
+ MinIO is already configured by the Docker setup. Nothing to do here.
593
+ </AlertDescription>
594
+ </Alert>
595
+ <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs text-muted-foreground">
596
+ <dt>Endpoint</dt>
597
+ <dd className="font-mono">{storage.endpoint}</dd>
598
+ <dt>Bucket</dt>
599
+ <dd className="font-mono">{storage.bucket}</dd>
600
+ <dt>Public URL</dt>
601
+ <dd className="font-mono">{storage.publicUrl}</dd>
602
+ </dl>
603
+ </div>
604
+ );
605
+ }
606
+
607
+ return (
608
+ <div className="space-y-4">
609
+ {channel === 'vercel' && (
610
+ <p className="text-xs text-muted-foreground">
611
+ Pre-filled for Supabase Storage. Create an S3 access key in your Supabase project
612
+ (Storage → S3 connection) and set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY in your Vercel
613
+ environment.
614
+ </p>
615
+ )}
616
+ <div className="grid gap-4 sm:grid-cols-2">
617
+ <Field label="Account / provider id" htmlFor="r2Account">
618
+ <Input
619
+ id="r2Account"
620
+ value={storage.accountId}
621
+ onChange={(e) => setStorage({ ...storage, accountId: e.target.value })}
622
+ />
623
+ </Field>
624
+ <Field label="Bucket" htmlFor="r2Bucket">
625
+ <Input
626
+ id="r2Bucket"
627
+ value={storage.bucket}
628
+ onChange={(e) => setStorage({ ...storage, bucket: e.target.value })}
629
+ />
630
+ </Field>
631
+ <Field label="Access key id" htmlFor="r2Access">
632
+ <Input
633
+ id="r2Access"
634
+ value={storage.accessKeyId}
635
+ onChange={(e) => setStorage({ ...storage, accessKeyId: e.target.value })}
636
+ />
637
+ </Field>
638
+ <Field label="Secret access key" htmlFor="r2Secret">
639
+ <Input
640
+ id="r2Secret"
641
+ type="password"
642
+ value={storage.secretAccessKey}
643
+ onChange={(e) => setStorage({ ...storage, secretAccessKey: e.target.value })}
644
+ />
645
+ </Field>
646
+ </div>
647
+ <Field label="Public bucket URL" htmlFor="r2Public">
648
+ <Input
649
+ id="r2Public"
650
+ placeholder="https://pub-xxxx.r2.dev"
651
+ value={storage.publicUrl}
652
+ onChange={(e) => setStorage({ ...storage, publicUrl: e.target.value })}
653
+ />
654
+ <p className="mt-1 text-xs text-muted-foreground">
655
+ Your bucket&apos;s public URL (Cloudflare R2 → your bucket → Public Development URL)
656
+ or a custom domain. Used to serve all media on your site.
657
+ </p>
658
+ </Field>
659
+ </div>
660
+ );
661
+ }
662
+
663
+ function Field({
664
+ label,
665
+ htmlFor,
666
+ children,
667
+ }: {
668
+ label: string;
669
+ htmlFor: string;
670
+ children: React.ReactNode;
671
+ }) {
672
+ return (
673
+ <div className="space-y-1.5">
674
+ <Label htmlFor={htmlFor}>{label}</Label>
675
+ {children}
676
+ </div>
677
+ );
678
+ }