@xk2800/nextjs-template 0.7.2-beta.10 → 0.7.2-beta.12
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/components/dashboard/admin/system-settings/system-settings-form.tsx +177 -162
- package/components/dashboard/admin/system-settings/system-settings-section.tsx +4 -2
- package/dist/api/feedback.js +18 -0
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +1 -1
- package/dist/api/marketing.js +18 -0
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +2 -2
- package/dist/auth/helpers.js +18 -0
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +2 -2
- package/dist/auth/index.js +18 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/{chunk-S23GC776.mjs → chunk-RK2B5AOQ.mjs} +3 -3
- package/dist/{chunk-S23GC776.mjs.map → chunk-RK2B5AOQ.mjs.map} +1 -1
- package/dist/{chunk-IH6CMZIN.mjs → chunk-ZQTI4T2K.mjs} +20 -2
- package/dist/chunk-ZQTI4T2K.mjs.map +1 -0
- package/package.json +1 -1
- package/scripts/check-deps.mjs +3 -1
- package/dist/chunk-IH6CMZIN.mjs.map +0 -1
|
@@ -20,9 +20,13 @@ interface ConfiguredAuthFlags {
|
|
|
20
20
|
oneTap: boolean
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export type SettingsSection = 'maintenance' | 'auth' | 'privacy' | 'diagnostics'
|
|
24
|
+
|
|
23
25
|
interface SystemSettingsFormProps {
|
|
24
26
|
initialSettings: SystemSettings
|
|
25
27
|
configuredFlags: ConfiguredAuthFlags
|
|
28
|
+
/** Which sections to show. Default: all four. Hide ones your app doesn't use (e.g. consent when it has its own banner wiring). */
|
|
29
|
+
sections?: SettingsSection[]
|
|
26
30
|
/** Per-control env requirements (see getControlStatuses); a failing one disables its toggle and explains why. */
|
|
27
31
|
controlStatus?: Record<string, ControlStatus>
|
|
28
32
|
}
|
|
@@ -38,7 +42,7 @@ type ToggleKey =
|
|
|
38
42
|
| 'feedbackAttachErrors'
|
|
39
43
|
| 'consentRequired'
|
|
40
44
|
|
|
41
|
-
const SECTIONS = [
|
|
45
|
+
const SECTIONS: { id: SettingsSection; label: string }[] = [
|
|
42
46
|
{ id: 'maintenance', label: 'Maintenance' },
|
|
43
47
|
{ id: 'auth', label: 'Auth & Sessions' },
|
|
44
48
|
{ id: 'privacy', label: 'Privacy & Consent' },
|
|
@@ -118,7 +122,10 @@ const LABELS: Record<ToggleKey, string> = {
|
|
|
118
122
|
consentRequired: 'Consent requirement',
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
const ALL_SECTIONS: SettingsSection[] = ['maintenance', 'auth', 'privacy', 'diagnostics']
|
|
126
|
+
|
|
127
|
+
export default function SystemSettingsForm({ initialSettings, configuredFlags, controlStatus = {}, sections = ALL_SECTIONS }: SystemSettingsFormProps) {
|
|
128
|
+
const show = (id: SettingsSection) => sections.includes(id)
|
|
122
129
|
const router = useRouter()
|
|
123
130
|
const [settings, setSettings] = useState(initialSettings)
|
|
124
131
|
const [rowState, setRowState] = useState<Partial<Record<ToggleKey, 'saving' | 'saved'>>>({})
|
|
@@ -179,184 +186,192 @@ export default function SystemSettingsForm({ initialSettings, configuredFlags, c
|
|
|
179
186
|
return (
|
|
180
187
|
<div className="space-y-6">
|
|
181
188
|
<nav className="sticky top-0 z-10 -mx-1 flex flex-wrap gap-1 rounded-lg border bg-background/90 p-1 backdrop-blur" aria-label="Settings sections">
|
|
182
|
-
{SECTIONS.map((sec) => (
|
|
189
|
+
{SECTIONS.filter((sec) => show(sec.id)).map((sec) => (
|
|
183
190
|
<a key={sec.id} href={`#${sec.id}`} className="rounded-md px-3 py-1.5 text-sm text-muted-foreground hover:bg-muted hover:text-foreground">
|
|
184
191
|
{sec.label}
|
|
185
192
|
</a>
|
|
186
193
|
))}
|
|
187
194
|
</nav>
|
|
188
195
|
|
|
189
|
-
|
|
190
|
-
<
|
|
191
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
<
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
<div className="space-y-2">
|
|
209
|
-
<Label htmlFor="maintenance-message">Message shown to visitors (optional)</Label>
|
|
210
|
-
<Textarea
|
|
211
|
-
id="maintenance-message"
|
|
212
|
-
value={settings.maintenanceMessage ?? ''}
|
|
213
|
-
onChange={(e) => setSettings({ ...settings, maintenanceMessage: e.target.value || null })}
|
|
214
|
-
placeholder="We'll be back shortly."
|
|
215
|
-
maxLength={2000}
|
|
196
|
+
{show('maintenance') && (
|
|
197
|
+
<Card id="maintenance" className="scroll-mt-16">
|
|
198
|
+
<CardHeader>
|
|
199
|
+
<CardTitle>Maintenance Mode</CardTitle>
|
|
200
|
+
<CardDescription>
|
|
201
|
+
Blocks every page and API route except the paths kept open below, and shows a
|
|
202
|
+
maintenance page instead — admins keep full access
|
|
203
|
+
</CardDescription>
|
|
204
|
+
</CardHeader>
|
|
205
|
+
<CardContent className="space-y-4">
|
|
206
|
+
<SettingRow
|
|
207
|
+
id="maintenance-toggle"
|
|
208
|
+
label="Maintenance mode"
|
|
209
|
+
description="Non-admins are redirected to /maintenance"
|
|
210
|
+
badge={settings.maintenanceMode ? <Badge variant="destructive">Site locked</Badge> : <Badge variant="outline">Off</Badge>}
|
|
211
|
+
checked={settings.maintenanceMode}
|
|
212
|
+
state={rowState.maintenanceMode}
|
|
213
|
+
onChange={(v) => saveToggle('maintenanceMode', v)}
|
|
216
214
|
/>
|
|
217
|
-
</div>
|
|
218
215
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
rows={6}
|
|
230
|
-
className="font-mono text-sm"
|
|
231
|
-
/>
|
|
232
|
-
</div>
|
|
216
|
+
<div className="space-y-2">
|
|
217
|
+
<Label htmlFor="maintenance-message">Message shown to visitors (optional)</Label>
|
|
218
|
+
<Textarea
|
|
219
|
+
id="maintenance-message"
|
|
220
|
+
value={settings.maintenanceMessage ?? ''}
|
|
221
|
+
onChange={(e) => setSettings({ ...settings, maintenanceMessage: e.target.value || null })}
|
|
222
|
+
placeholder="We'll be back shortly."
|
|
223
|
+
maxLength={2000}
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
233
226
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
</Card>
|
|
227
|
+
<div className="space-y-2">
|
|
228
|
+
<Label htmlFor="maintenance-exempt">Paths that stay open during maintenance</Label>
|
|
229
|
+
<p className="text-sm text-gray-500">
|
|
230
|
+
One per line. <code>/foo</code> also opens <code>/foo/...</code>; <code>/</code> opens
|
|
231
|
+
only the home page. Always open regardless: {ALWAYS_OPEN_PATHS.join(', ')}
|
|
232
|
+
</p>
|
|
233
|
+
<Textarea
|
|
234
|
+
id="maintenance-exempt"
|
|
235
|
+
value={exemptPathsText}
|
|
236
|
+
onChange={(e) => setExemptPathsText(e.target.value)}
|
|
237
|
+
rows={6}
|
|
238
|
+
className="font-mono text-sm"
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
249
241
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
onChange={(v) => saveToggle('authEnableGoogle', v)}
|
|
267
|
-
/>
|
|
242
|
+
<div className="flex items-center justify-between gap-2">
|
|
243
|
+
<Button
|
|
244
|
+
type="button"
|
|
245
|
+
variant="outline"
|
|
246
|
+
size="sm"
|
|
247
|
+
onClick={() => setExemptPathsText(DEFAULT_MAINTENANCE_EXEMPT_PATHS.join('\n'))}
|
|
248
|
+
>
|
|
249
|
+
Reset to public pages
|
|
250
|
+
</Button>
|
|
251
|
+
<Button size="sm" onClick={saveMaintenanceText} disabled={isSavingMaintenance}>
|
|
252
|
+
{isSavingMaintenance ? 'Saving...' : 'Save message & paths'}
|
|
253
|
+
</Button>
|
|
254
|
+
</div>
|
|
255
|
+
</CardContent>
|
|
256
|
+
</Card>
|
|
257
|
+
)}
|
|
268
258
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
259
|
+
{show('auth') && (
|
|
260
|
+
<Card id="auth" className="scroll-mt-16">
|
|
261
|
+
<CardHeader>
|
|
262
|
+
<CardTitle>Authentication & Sessions</CardTitle>
|
|
263
|
+
<CardDescription>
|
|
264
|
+
Live toggles on top of what's configured via environment variables —
|
|
265
|
+
a method disabled here stops working immediately, without a redeploy
|
|
266
|
+
</CardDescription>
|
|
267
|
+
</CardHeader>
|
|
268
|
+
<CardContent className="space-y-4">
|
|
269
|
+
<SettingRow
|
|
270
|
+
id="google-toggle"
|
|
271
|
+
label="Google sign-in"
|
|
272
|
+
description="Show the Google button and accept sign-ins"
|
|
273
|
+
{...envProps(controlStatus.authEnableGoogle, settings.authEnableGoogle)}
|
|
274
|
+
checked={settings.authEnableGoogle}
|
|
275
|
+
state={rowState.authEnableGoogle}
|
|
276
|
+
onChange={(v) => saveToggle('authEnableGoogle', v)}
|
|
277
|
+
/>
|
|
278
278
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
)}
|
|
289
|
-
checked={settings.authEnableOneTap}
|
|
290
|
-
state={rowState.authEnableOneTap}
|
|
291
|
-
onChange={(v) => saveToggle('authEnableOneTap', v)}
|
|
292
|
-
/>
|
|
279
|
+
<SettingRow
|
|
280
|
+
id="email-toggle"
|
|
281
|
+
label="Email & password sign-in"
|
|
282
|
+
description="Show the email/password form and signup page"
|
|
283
|
+
{...envProps(controlStatus.authEnableEmailPassword, settings.authEnableEmailPassword)}
|
|
284
|
+
checked={settings.authEnableEmailPassword}
|
|
285
|
+
state={rowState.authEnableEmailPassword}
|
|
286
|
+
onChange={(v) => saveToggle('authEnableEmailPassword', v)}
|
|
287
|
+
/>
|
|
293
288
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
289
|
+
<SettingRow
|
|
290
|
+
id="onetap-toggle"
|
|
291
|
+
label="Google One Tap"
|
|
292
|
+
description="Show the One Tap prompt on load — a shortcut into Google sign-in, not a separate method; it stops working if Google sign-in above is off"
|
|
293
|
+
{...envProps(controlStatus.authEnableOneTap, settings.authEnableOneTap)}
|
|
294
|
+
note={!settings.authEnableGoogle && (
|
|
295
|
+
<p className="text-sm text-amber-600 dark:text-amber-500">
|
|
296
|
+
Requires Google sign-in to be enabled above
|
|
297
|
+
</p>
|
|
298
|
+
)}
|
|
299
|
+
checked={settings.authEnableOneTap}
|
|
300
|
+
state={rowState.authEnableOneTap}
|
|
301
|
+
onChange={(v) => saveToggle('authEnableOneTap', v)}
|
|
302
|
+
/>
|
|
302
303
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
304
|
+
<SettingRow
|
|
305
|
+
id="revoke-toggle"
|
|
306
|
+
label="Session revocation"
|
|
307
|
+
description="Let users revoke their own sessions from Settings"
|
|
308
|
+
checked={settings.enableSessionRevocation}
|
|
309
|
+
state={rowState.enableSessionRevocation}
|
|
310
|
+
onChange={(v) => saveToggle('enableSessionRevocation', v)}
|
|
311
|
+
/>
|
|
310
312
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
<CardDescription>
|
|
315
|
-
Whether visitors must opt in before device fingerprinting and Google One Tap run
|
|
316
|
-
</CardDescription>
|
|
317
|
-
</CardHeader>
|
|
318
|
-
<CardContent className="space-y-4">
|
|
319
|
-
<SettingRow
|
|
320
|
-
id="consent-toggle"
|
|
321
|
-
label="Require consent (GDPR / ePrivacy)"
|
|
322
|
-
description="On: cookie banner where visitors allow fingerprinting and One Tap separately, and the device record is erased if fingerprint consent is withdrawn. Off: no banner, everything runs for every visitor."
|
|
323
|
-
note={!settings.consentRequired && (
|
|
324
|
-
<p className="text-sm text-amber-600 dark:text-amber-500">
|
|
325
|
-
Only turn this off if none of your users are in the EU, the UK or another region with
|
|
326
|
-
consent rules. Fingerprinting without consent breaks those laws.
|
|
313
|
+
{!anySignInMethodLeft && (
|
|
314
|
+
<p className="text-sm text-destructive">
|
|
315
|
+
At least one sign-in method must stay enabled, or nobody will be able to sign in.
|
|
327
316
|
</p>
|
|
328
317
|
)}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
/>
|
|
333
|
-
</CardContent>
|
|
334
|
-
</Card>
|
|
318
|
+
</CardContent>
|
|
319
|
+
</Card>
|
|
320
|
+
)}
|
|
335
321
|
|
|
336
|
-
|
|
337
|
-
<
|
|
338
|
-
<
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
<
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
322
|
+
{show('privacy') && (
|
|
323
|
+
<Card id="privacy" className="scroll-mt-16">
|
|
324
|
+
<CardHeader>
|
|
325
|
+
<CardTitle>Privacy & Consent</CardTitle>
|
|
326
|
+
<CardDescription>
|
|
327
|
+
Whether visitors must opt in before device fingerprinting and Google One Tap run
|
|
328
|
+
</CardDescription>
|
|
329
|
+
</CardHeader>
|
|
330
|
+
<CardContent className="space-y-4">
|
|
331
|
+
<SettingRow
|
|
332
|
+
id="consent-toggle"
|
|
333
|
+
label="Require consent (GDPR / ePrivacy)"
|
|
334
|
+
description="On: cookie banner where visitors allow fingerprinting and One Tap separately, and the device record is erased if fingerprint consent is withdrawn. Off: no banner, everything runs for every visitor."
|
|
335
|
+
note={!settings.consentRequired && (
|
|
336
|
+
<p className="text-sm text-amber-600 dark:text-amber-500">
|
|
337
|
+
Only turn this off if none of your users are in the EU, the UK or another region with
|
|
338
|
+
consent rules. Fingerprinting without consent breaks those laws.
|
|
339
|
+
</p>
|
|
340
|
+
)}
|
|
341
|
+
checked={settings.consentRequired ?? true}
|
|
342
|
+
state={rowState.consentRequired}
|
|
343
|
+
onChange={(v) => saveToggle('consentRequired', v)}
|
|
344
|
+
/>
|
|
345
|
+
</CardContent>
|
|
346
|
+
</Card>
|
|
347
|
+
)}
|
|
348
|
+
|
|
349
|
+
{show('diagnostics') && (
|
|
350
|
+
<Card id="diagnostics" className="scroll-mt-16">
|
|
351
|
+
<CardHeader>
|
|
352
|
+
<CardTitle>Integrations & Diagnostics</CardTitle>
|
|
353
|
+
<CardDescription>
|
|
354
|
+
Feedback reporting (applies when FEEDBACK_DISCORD_WEBHOOK_URL or FEEDBACK_EMAIL is set) and developer test tools
|
|
355
|
+
</CardDescription>
|
|
356
|
+
</CardHeader>
|
|
357
|
+
<CardContent className="space-y-4">
|
|
358
|
+
<SettingRow
|
|
359
|
+
id="feedback-errors-toggle"
|
|
360
|
+
label="Attach error details"
|
|
361
|
+
description="When a user reports a problem from an error, send the error message with their report, even if they edit it out of the text"
|
|
362
|
+
{...envProps(controlStatus.feedbackAttachErrors, settings.feedbackAttachErrors)}
|
|
363
|
+
checked={settings.feedbackAttachErrors}
|
|
364
|
+
state={rowState.feedbackAttachErrors}
|
|
365
|
+
onChange={(v) => saveToggle('feedbackAttachErrors', v)}
|
|
366
|
+
/>
|
|
367
|
+
{process.env.NODE_ENV === "development" ? (
|
|
368
|
+
<FeedbackTestForm />
|
|
369
|
+
) : (
|
|
370
|
+
<p className="text-sm text-muted-foreground">Error-pipeline test tools are available in development builds.</p>
|
|
371
|
+
)}
|
|
372
|
+
</CardContent>
|
|
373
|
+
</Card>
|
|
374
|
+
)}
|
|
360
375
|
</div>
|
|
361
376
|
)
|
|
362
377
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getSystemSettings, getConfiguredAuthFlags, getControlStatuses, isConsentRequired } from "@xk2800/nextjs-template/settings/queries"
|
|
2
|
-
import SystemSettingsForm from "./system-settings-form"
|
|
2
|
+
import SystemSettingsForm, { type SettingsSection } from "./system-settings-form"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** Admin settings page body. `sections` limits which parts show (default: all). */
|
|
5
|
+
export default async function SystemSettingsSection({ sections }: { sections?: SettingsSection[] } = {}) {
|
|
5
6
|
const settings = await getSystemSettings()
|
|
6
7
|
const configuredFlags = getConfiguredAuthFlags()
|
|
7
8
|
|
|
@@ -11,6 +12,7 @@ export default async function SystemSettingsSection() {
|
|
|
11
12
|
initialSettings={{ ...settings, consentRequired: isConsentRequired(settings) }}
|
|
12
13
|
configuredFlags={configuredFlags}
|
|
13
14
|
controlStatus={getControlStatuses()}
|
|
15
|
+
sections={sections}
|
|
14
16
|
/>
|
|
15
17
|
)
|
|
16
18
|
}
|
package/dist/api/feedback.js
CHANGED
|
@@ -6,6 +6,9 @@ require('server-only');
|
|
|
6
6
|
var server = require('next/server');
|
|
7
7
|
var headers = require('next/headers');
|
|
8
8
|
var zod = require('zod');
|
|
9
|
+
var child_process = require('child_process');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
9
12
|
var betterAuth = require('better-auth');
|
|
10
13
|
var drizzle = require('better-auth/adapters/drizzle');
|
|
11
14
|
var cuid2 = require('@paralleldrive/cuid2');
|
|
@@ -1162,6 +1165,21 @@ async function getResend() {
|
|
|
1162
1165
|
config.RESEND_BROADCAST_API_KEY || config.RESEND_API_KEY;
|
|
1163
1166
|
|
|
1164
1167
|
// server/auth.ts
|
|
1168
|
+
function checkDepsOnce() {
|
|
1169
|
+
const flag = globalThis;
|
|
1170
|
+
if (process.env.NODE_ENV !== "development" || flag.__xkDepsChecked) return;
|
|
1171
|
+
flag.__xkDepsChecked = true;
|
|
1172
|
+
const script = path.join(
|
|
1173
|
+
/*turbopackIgnore: true*/
|
|
1174
|
+
process.cwd(),
|
|
1175
|
+
"node_modules/@xk2800/nextjs-template/scripts/check-deps.mjs"
|
|
1176
|
+
);
|
|
1177
|
+
if (!fs.existsSync(script)) return;
|
|
1178
|
+
child_process.execFile(process.execPath, [script], (_err, stdout) => {
|
|
1179
|
+
if (stdout == null ? void 0 : stdout.trim()) console.log(stdout);
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
checkDepsOnce();
|
|
1165
1183
|
async function logFailedLogin(ctx, log) {
|
|
1166
1184
|
var _a, _b, _c;
|
|
1167
1185
|
try {
|