@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
- package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
- package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
- package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
- package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
- package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
- package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
- package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
- package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
- package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
- package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
- package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
- package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
- package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
- package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
- package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
- package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
- package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
- package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
- package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
- package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
- package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
- package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
- package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
- package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
- package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
- package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
- package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
- package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
- package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
- package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
- package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
- package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
- package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
- package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
- package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
- package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
- package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
- package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
- package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
- package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
- package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
- package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
- package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
- package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
- package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
- package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
- package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
- package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
- package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
- package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
- package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
- package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
- package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
- package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
- package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
- package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
- package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
- package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
- package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
- package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
- package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
- package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
- package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
- package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
- package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
- package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
- package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
- package/components/email/team/workspace-invite.tsx +51 -0
- package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
- package/components/error-boundary.tsx +32 -0
- package/components/settings/appearance/appearance-section.tsx +64 -0
- package/components/settings/index.ts +5 -0
- package/components/settings/notifications/notifications-section.tsx +31 -0
- package/components/settings/profile/profile-section.tsx +38 -0
- package/components/settings/security/security-section.tsx +24 -0
- package/components/settings/settings-nav.tsx +35 -0
- package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
- package/components/site/push/push-notifications-card.tsx +117 -0
- package/components/ui/collapsible.tsx +9 -0
- package/components/ui/column-picker.tsx +1 -1
- package/components/ui/data-table.tsx +1 -1
- package/components/ui/dialog.tsx +46 -13
- package/components/ui/drawer.tsx +88 -0
- package/components/ui/tabs.tsx +52 -0
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +66 -15
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +32 -21
- package/dist/activity/queries.d.ts +32 -21
- package/dist/activity/queries.js +86 -22
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +27 -14
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +48 -17
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +9 -9
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +302 -248
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +320 -266
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +16 -25
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +60 -18
- package/dist/auth/helpers.d.ts +60 -18
- package/dist/auth/helpers.js +332 -267
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +86 -47
- package/dist/auth/index.d.ts +86 -47
- package/dist/auth/index.js +296 -244
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1215 -2527
- package/dist/auth-client/index.d.ts +1215 -2527
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-TE5BEAQB.mjs → chunk-3BH6BVBQ.mjs} +17 -7
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/chunk-DWLMCMXF.mjs.map +1 -0
- package/dist/{chunk-653GF7OT.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-2BJ3B4FR.mjs → chunk-NJBRKKLK.mjs} +46 -7
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-H3XZTZ5K.mjs → chunk-RK2B5AOQ.mjs} +41 -29
- package/dist/chunk-RK2B5AOQ.mjs.map +1 -0
- package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/chunk-TIR7KHXL.mjs.map +1 -0
- package/dist/{chunk-O5EQYHNC.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/{chunk-EIS4SCQW.mjs → chunk-ZQTI4T2K.mjs} +231 -220
- package/dist/chunk-ZQTI4T2K.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +61 -12
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -4
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +62 -13
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +14 -4
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
- package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
- package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
- package/dist/reset-password-64VQEXBW.mjs.map +1 -0
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +61 -12
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/sessions/queries.mjs.map +1 -1
- package/dist/settings/queries.d.mts +11 -2
- package/dist/settings/queries.d.ts +11 -2
- package/dist/settings/queries.js +84 -13
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +41 -21
- package/dist/users/queries.d.ts +41 -21
- package/dist/users/queries.js +117 -23
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +57 -17
- package/dist/users/queries.mjs.map +1 -1
- package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
- package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
- package/lib/{auth-client.ts → auth/client.ts} +22 -2
- package/lib/push/client.ts +39 -0
- package/lib/security/activity-severity.ts +57 -0
- package/lib/{request-info.ts → utils/request-info.ts} +7 -3
- package/package.json +177 -75
- package/scripts/check-deps.mjs +68 -0
- package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
- package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
- package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
- package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
- package/dist/chunk-653GF7OT.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-EIS4SCQW.mjs.map +0 -1
- package/dist/chunk-H3XZTZ5K.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-K62JYJRR.mjs +0 -30
- package/dist/chunk-K62JYJRR.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-O5EQYHNC.mjs.map +0 -1
- package/dist/chunk-TE5BEAQB.mjs.map +0 -1
- package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
- package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
- package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
- /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
- /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
- /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
- /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
- /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
- /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
- /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
- /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
- /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
- /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
- /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
- /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
- /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
- /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
- /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useRef, useState, type ReactNode } from "react"
|
|
4
|
+
import { useRouter } from "next/navigation"
|
|
5
|
+
import { Check, Loader2 } from "lucide-react"
|
|
6
|
+
import { toast } from "sonner"
|
|
7
|
+
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../../../ui/card"
|
|
8
|
+
import { Switch } from "../../../ui/switch"
|
|
9
|
+
import { Label } from "../../../ui/label"
|
|
10
|
+
import { Textarea } from "../../../ui/textarea"
|
|
11
|
+
import { Button } from "../../../ui/button"
|
|
12
|
+
import { Badge } from "../../../ui/badge"
|
|
13
|
+
import type { SystemSettings } from "@xk2800/nextjs-template/settings/queries"
|
|
14
|
+
import FeedbackTestForm from "./feedback-test-form"
|
|
15
|
+
import { ALWAYS_OPEN_PATHS, DEFAULT_MAINTENANCE_EXEMPT_PATHS } from "../../../../lib/config/maintenance"
|
|
16
|
+
|
|
17
|
+
interface ConfiguredAuthFlags {
|
|
18
|
+
google: boolean
|
|
19
|
+
emailPassword: boolean
|
|
20
|
+
oneTap: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface SystemSettingsFormProps {
|
|
24
|
+
initialSettings: SystemSettings
|
|
25
|
+
configuredFlags: ConfiguredAuthFlags
|
|
26
|
+
/** Per-control env requirements (see getControlStatuses); a failing one disables its toggle and explains why. */
|
|
27
|
+
controlStatus?: Record<string, ControlStatus>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type ControlStatus = { ok: true } | { ok: false; kind: 'flag' | 'keys'; reason: string }
|
|
31
|
+
|
|
32
|
+
type ToggleKey =
|
|
33
|
+
| 'maintenanceMode'
|
|
34
|
+
| 'authEnableGoogle'
|
|
35
|
+
| 'authEnableEmailPassword'
|
|
36
|
+
| 'authEnableOneTap'
|
|
37
|
+
| 'enableSessionRevocation'
|
|
38
|
+
| 'feedbackAttachErrors'
|
|
39
|
+
| 'consentRequired'
|
|
40
|
+
|
|
41
|
+
const SECTIONS = [
|
|
42
|
+
{ id: 'maintenance', label: 'Maintenance' },
|
|
43
|
+
{ id: 'auth', label: 'Auth & Sessions' },
|
|
44
|
+
{ id: 'privacy', label: 'Privacy & Consent' },
|
|
45
|
+
{ id: 'diagnostics', label: 'Diagnostics' },
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
// One switch row: label, description, optional badges/notes, and an inline
|
|
49
|
+
// Saving... / Saved indicator next to the switch.
|
|
50
|
+
function SettingRow({
|
|
51
|
+
id, label, description, badge, note, blockedNote, checked, disabled, state, onChange,
|
|
52
|
+
}: {
|
|
53
|
+
id: string
|
|
54
|
+
label: ReactNode
|
|
55
|
+
description: ReactNode
|
|
56
|
+
badge?: ReactNode
|
|
57
|
+
note?: ReactNode
|
|
58
|
+
/** Shown first, and explains why the switch is disabled. */
|
|
59
|
+
blockedNote?: ReactNode
|
|
60
|
+
checked: boolean
|
|
61
|
+
disabled?: boolean
|
|
62
|
+
state?: 'saving' | 'saved'
|
|
63
|
+
onChange: (checked: boolean) => void
|
|
64
|
+
}) {
|
|
65
|
+
return (
|
|
66
|
+
<div className="flex items-center justify-between gap-4">
|
|
67
|
+
<div className="space-y-1">
|
|
68
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
69
|
+
<Label htmlFor={id}>{label}</Label>
|
|
70
|
+
{badge}
|
|
71
|
+
</div>
|
|
72
|
+
<p className="text-sm text-gray-500">{description}</p>
|
|
73
|
+
{blockedNote}
|
|
74
|
+
{note}
|
|
75
|
+
</div>
|
|
76
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
77
|
+
{state === 'saving' && (
|
|
78
|
+
<span className="flex items-center gap-1 text-xs text-muted-foreground"><Loader2 className="size-3 animate-spin" /> Saving...</span>
|
|
79
|
+
)}
|
|
80
|
+
{state === 'saved' && (
|
|
81
|
+
<span className="flex items-center gap-1 text-xs text-emerald-600 dark:text-emerald-400"><Check className="size-3" /> Saved</span>
|
|
82
|
+
)}
|
|
83
|
+
{/* A control the environment blocks can't be on, whatever the stored value says. */}
|
|
84
|
+
<Switch id={id} checked={checked && !blockedNote} disabled={disabled || state === 'saving'} onCheckedChange={onChange} />
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Badge + note + disabled flag for a control, derived from its env requirements.
|
|
91
|
+
function envProps(status: ControlStatus | undefined, on: boolean) {
|
|
92
|
+
if (!status) return {}
|
|
93
|
+
if (status.ok) {
|
|
94
|
+
return {
|
|
95
|
+
badge: on
|
|
96
|
+
? <Badge variant="outline" className="border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400">Ready</Badge>
|
|
97
|
+
: <Badge variant="outline">Off</Badge>,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
disabled: true,
|
|
102
|
+
badge: (
|
|
103
|
+
<Badge variant="outline" className="border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400">
|
|
104
|
+
{status.kind === 'flag' ? 'Disabled in ENV' : 'Missing key'}
|
|
105
|
+
</Badge>
|
|
106
|
+
),
|
|
107
|
+
blockedNote: <p className="text-sm text-amber-600 dark:text-amber-500">Disabled: {status.reason}</p>,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const LABELS: Record<ToggleKey, string> = {
|
|
112
|
+
maintenanceMode: 'Maintenance mode',
|
|
113
|
+
authEnableGoogle: 'Google sign-in',
|
|
114
|
+
authEnableEmailPassword: 'Email & password sign-in',
|
|
115
|
+
authEnableOneTap: 'Google One Tap',
|
|
116
|
+
enableSessionRevocation: 'Session revocation',
|
|
117
|
+
feedbackAttachErrors: 'Attach error details',
|
|
118
|
+
consentRequired: 'Consent requirement',
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default function SystemSettingsForm({ initialSettings, configuredFlags, controlStatus = {} }: SystemSettingsFormProps) {
|
|
122
|
+
const router = useRouter()
|
|
123
|
+
const [settings, setSettings] = useState(initialSettings)
|
|
124
|
+
const [rowState, setRowState] = useState<Partial<Record<ToggleKey, 'saving' | 'saved'>>>({})
|
|
125
|
+
const [isSavingMaintenance, setIsSavingMaintenance] = useState(false)
|
|
126
|
+
const [exemptPathsText, setExemptPathsText] = useState(initialSettings.maintenanceExemptPaths.join('\n'))
|
|
127
|
+
const exemptPaths = exemptPathsText.split('\n').map((p) => p.trim()).filter(Boolean)
|
|
128
|
+
const savedTimers = useRef<Partial<Record<ToggleKey, ReturnType<typeof setTimeout>>>>({})
|
|
129
|
+
|
|
130
|
+
// "Left enabled" means actually usable — configured (env) AND toggled on
|
|
131
|
+
// (DB) — not just the DB toggle, which can look "on" while being fully
|
|
132
|
+
// inert if the env var for that method is off.
|
|
133
|
+
const anySignInMethodLeft =
|
|
134
|
+
(configuredFlags.google && settings.authEnableGoogle) ||
|
|
135
|
+
(configuredFlags.emailPassword && settings.authEnableEmailPassword)
|
|
136
|
+
|
|
137
|
+
const patch = async (body: Record<string, unknown>) => {
|
|
138
|
+
const response = await fetch('/api/admin/settings', {
|
|
139
|
+
method: 'PATCH',
|
|
140
|
+
headers: { 'Content-Type': 'application/json' },
|
|
141
|
+
body: JSON.stringify(body),
|
|
142
|
+
})
|
|
143
|
+
const data = await response.json().catch(() => ({}))
|
|
144
|
+
if (!response.ok) throw new Error(data.error || 'Failed to save settings')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Switches save on change (optimistic, reverted if the server refuses).
|
|
148
|
+
const saveToggle = async (key: ToggleKey, value: boolean) => {
|
|
149
|
+
const previous = settings[key]
|
|
150
|
+
clearTimeout(savedTimers.current[key])
|
|
151
|
+
setSettings((s) => ({ ...s, [key]: value }))
|
|
152
|
+
setRowState((r) => ({ ...r, [key]: 'saving' }))
|
|
153
|
+
try {
|
|
154
|
+
await patch({ [key]: value })
|
|
155
|
+
setRowState((r) => ({ ...r, [key]: 'saved' }))
|
|
156
|
+
savedTimers.current[key] = setTimeout(() => setRowState((r) => ({ ...r, [key]: undefined })), 2000)
|
|
157
|
+
toast.success(`${LABELS[key]} updated`)
|
|
158
|
+
router.refresh()
|
|
159
|
+
} catch (error) {
|
|
160
|
+
setSettings((s) => ({ ...s, [key]: previous }))
|
|
161
|
+
setRowState((r) => ({ ...r, [key]: undefined }))
|
|
162
|
+
toast.error(error instanceof Error ? error.message : 'Failed to save settings')
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const saveMaintenanceText = async () => {
|
|
167
|
+
setIsSavingMaintenance(true)
|
|
168
|
+
try {
|
|
169
|
+
await patch({ maintenanceMessage: settings.maintenanceMessage, maintenanceExemptPaths: exemptPaths })
|
|
170
|
+
toast.success('Maintenance settings saved')
|
|
171
|
+
router.refresh()
|
|
172
|
+
} catch (error) {
|
|
173
|
+
toast.error(error instanceof Error ? error.message : 'Failed to save settings')
|
|
174
|
+
} finally {
|
|
175
|
+
setIsSavingMaintenance(false)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<div className="space-y-6">
|
|
181
|
+
<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) => (
|
|
183
|
+
<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
|
+
{sec.label}
|
|
185
|
+
</a>
|
|
186
|
+
))}
|
|
187
|
+
</nav>
|
|
188
|
+
|
|
189
|
+
<Card id="maintenance" className="scroll-mt-16">
|
|
190
|
+
<CardHeader>
|
|
191
|
+
<CardTitle>Maintenance Mode</CardTitle>
|
|
192
|
+
<CardDescription>
|
|
193
|
+
Blocks every page and API route except the paths kept open below, and shows a
|
|
194
|
+
maintenance page instead — admins keep full access
|
|
195
|
+
</CardDescription>
|
|
196
|
+
</CardHeader>
|
|
197
|
+
<CardContent className="space-y-4">
|
|
198
|
+
<SettingRow
|
|
199
|
+
id="maintenance-toggle"
|
|
200
|
+
label="Maintenance mode"
|
|
201
|
+
description="Non-admins are redirected to /maintenance"
|
|
202
|
+
badge={settings.maintenanceMode ? <Badge variant="destructive">Site locked</Badge> : <Badge variant="outline">Off</Badge>}
|
|
203
|
+
checked={settings.maintenanceMode}
|
|
204
|
+
state={rowState.maintenanceMode}
|
|
205
|
+
onChange={(v) => saveToggle('maintenanceMode', v)}
|
|
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}
|
|
216
|
+
/>
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
<div className="space-y-2">
|
|
220
|
+
<Label htmlFor="maintenance-exempt">Paths that stay open during maintenance</Label>
|
|
221
|
+
<p className="text-sm text-gray-500">
|
|
222
|
+
One per line. <code>/foo</code> also opens <code>/foo/...</code>; <code>/</code> opens
|
|
223
|
+
only the home page. Always open regardless: {ALWAYS_OPEN_PATHS.join(', ')}
|
|
224
|
+
</p>
|
|
225
|
+
<Textarea
|
|
226
|
+
id="maintenance-exempt"
|
|
227
|
+
value={exemptPathsText}
|
|
228
|
+
onChange={(e) => setExemptPathsText(e.target.value)}
|
|
229
|
+
rows={6}
|
|
230
|
+
className="font-mono text-sm"
|
|
231
|
+
/>
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<div className="flex items-center justify-between gap-2">
|
|
235
|
+
<Button
|
|
236
|
+
type="button"
|
|
237
|
+
variant="outline"
|
|
238
|
+
size="sm"
|
|
239
|
+
onClick={() => setExemptPathsText(DEFAULT_MAINTENANCE_EXEMPT_PATHS.join('\n'))}
|
|
240
|
+
>
|
|
241
|
+
Reset to public pages
|
|
242
|
+
</Button>
|
|
243
|
+
<Button size="sm" onClick={saveMaintenanceText} disabled={isSavingMaintenance}>
|
|
244
|
+
{isSavingMaintenance ? 'Saving...' : 'Save message & paths'}
|
|
245
|
+
</Button>
|
|
246
|
+
</div>
|
|
247
|
+
</CardContent>
|
|
248
|
+
</Card>
|
|
249
|
+
|
|
250
|
+
<Card id="auth" className="scroll-mt-16">
|
|
251
|
+
<CardHeader>
|
|
252
|
+
<CardTitle>Authentication & Sessions</CardTitle>
|
|
253
|
+
<CardDescription>
|
|
254
|
+
Live toggles on top of what's configured via environment variables —
|
|
255
|
+
a method disabled here stops working immediately, without a redeploy
|
|
256
|
+
</CardDescription>
|
|
257
|
+
</CardHeader>
|
|
258
|
+
<CardContent className="space-y-4">
|
|
259
|
+
<SettingRow
|
|
260
|
+
id="google-toggle"
|
|
261
|
+
label="Google sign-in"
|
|
262
|
+
description="Show the Google button and accept sign-ins"
|
|
263
|
+
{...envProps(controlStatus.authEnableGoogle, settings.authEnableGoogle)}
|
|
264
|
+
checked={settings.authEnableGoogle}
|
|
265
|
+
state={rowState.authEnableGoogle}
|
|
266
|
+
onChange={(v) => saveToggle('authEnableGoogle', v)}
|
|
267
|
+
/>
|
|
268
|
+
|
|
269
|
+
<SettingRow
|
|
270
|
+
id="email-toggle"
|
|
271
|
+
label="Email & password sign-in"
|
|
272
|
+
description="Show the email/password form and signup page"
|
|
273
|
+
{...envProps(controlStatus.authEnableEmailPassword, settings.authEnableEmailPassword)}
|
|
274
|
+
checked={settings.authEnableEmailPassword}
|
|
275
|
+
state={rowState.authEnableEmailPassword}
|
|
276
|
+
onChange={(v) => saveToggle('authEnableEmailPassword', v)}
|
|
277
|
+
/>
|
|
278
|
+
|
|
279
|
+
<SettingRow
|
|
280
|
+
id="onetap-toggle"
|
|
281
|
+
label="Google One Tap"
|
|
282
|
+
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"
|
|
283
|
+
{...envProps(controlStatus.authEnableOneTap, settings.authEnableOneTap)}
|
|
284
|
+
note={!settings.authEnableGoogle && (
|
|
285
|
+
<p className="text-sm text-amber-600 dark:text-amber-500">
|
|
286
|
+
Requires Google sign-in to be enabled above
|
|
287
|
+
</p>
|
|
288
|
+
)}
|
|
289
|
+
checked={settings.authEnableOneTap}
|
|
290
|
+
state={rowState.authEnableOneTap}
|
|
291
|
+
onChange={(v) => saveToggle('authEnableOneTap', v)}
|
|
292
|
+
/>
|
|
293
|
+
|
|
294
|
+
<SettingRow
|
|
295
|
+
id="revoke-toggle"
|
|
296
|
+
label="Session revocation"
|
|
297
|
+
description="Let users revoke their own sessions from Settings"
|
|
298
|
+
checked={settings.enableSessionRevocation}
|
|
299
|
+
state={rowState.enableSessionRevocation}
|
|
300
|
+
onChange={(v) => saveToggle('enableSessionRevocation', v)}
|
|
301
|
+
/>
|
|
302
|
+
|
|
303
|
+
{!anySignInMethodLeft && (
|
|
304
|
+
<p className="text-sm text-destructive">
|
|
305
|
+
At least one sign-in method must stay enabled, or nobody will be able to sign in.
|
|
306
|
+
</p>
|
|
307
|
+
)}
|
|
308
|
+
</CardContent>
|
|
309
|
+
</Card>
|
|
310
|
+
|
|
311
|
+
<Card id="privacy" className="scroll-mt-16">
|
|
312
|
+
<CardHeader>
|
|
313
|
+
<CardTitle>Privacy & Consent</CardTitle>
|
|
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.
|
|
327
|
+
</p>
|
|
328
|
+
)}
|
|
329
|
+
checked={settings.consentRequired ?? true}
|
|
330
|
+
state={rowState.consentRequired}
|
|
331
|
+
onChange={(v) => saveToggle('consentRequired', v)}
|
|
332
|
+
/>
|
|
333
|
+
</CardContent>
|
|
334
|
+
</Card>
|
|
335
|
+
|
|
336
|
+
<Card id="diagnostics" className="scroll-mt-16">
|
|
337
|
+
<CardHeader>
|
|
338
|
+
<CardTitle>Integrations & Diagnostics</CardTitle>
|
|
339
|
+
<CardDescription>
|
|
340
|
+
Feedback reporting (applies when FEEDBACK_DISCORD_WEBHOOK_URL or FEEDBACK_EMAIL is set) and developer test tools
|
|
341
|
+
</CardDescription>
|
|
342
|
+
</CardHeader>
|
|
343
|
+
<CardContent className="space-y-4">
|
|
344
|
+
<SettingRow
|
|
345
|
+
id="feedback-errors-toggle"
|
|
346
|
+
label="Attach error details"
|
|
347
|
+
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"
|
|
348
|
+
{...envProps(controlStatus.feedbackAttachErrors, settings.feedbackAttachErrors)}
|
|
349
|
+
checked={settings.feedbackAttachErrors}
|
|
350
|
+
state={rowState.feedbackAttachErrors}
|
|
351
|
+
onChange={(v) => saveToggle('feedbackAttachErrors', v)}
|
|
352
|
+
/>
|
|
353
|
+
{process.env.NODE_ENV === "development" ? (
|
|
354
|
+
<FeedbackTestForm />
|
|
355
|
+
) : (
|
|
356
|
+
<p className="text-sm text-muted-foreground">Error-pipeline test tools are available in development builds.</p>
|
|
357
|
+
)}
|
|
358
|
+
</CardContent>
|
|
359
|
+
</Card>
|
|
360
|
+
</div>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getSystemSettings, getConfiguredAuthFlags, isConsentRequired } from "@xk2800/nextjs-template/settings/queries"
|
|
2
|
-
import SystemSettingsForm from "./
|
|
1
|
+
import { getSystemSettings, getConfiguredAuthFlags, getControlStatuses, isConsentRequired } from "@xk2800/nextjs-template/settings/queries"
|
|
2
|
+
import SystemSettingsForm from "./system-settings-form"
|
|
3
3
|
|
|
4
4
|
export default async function SystemSettingsSection() {
|
|
5
5
|
const settings = await getSystemSettings()
|
|
@@ -10,6 +10,7 @@ export default async function SystemSettingsSection() {
|
|
|
10
10
|
<SystemSettingsForm
|
|
11
11
|
initialSettings={{ ...settings, consentRequired: isConsentRequired(settings) }}
|
|
12
12
|
configuredFlags={configuredFlags}
|
|
13
|
+
controlStatus={getControlStatuses()}
|
|
13
14
|
/>
|
|
14
15
|
)
|
|
15
16
|
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useState, type ReactNode } from 'react'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import { toast } from 'sonner'
|
|
6
|
+
import { Button } from '../../../ui/button'
|
|
7
|
+
import { Input } from '../../../ui/input'
|
|
8
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../../ui/select'
|
|
9
|
+
import {
|
|
10
|
+
AlertDialog,
|
|
11
|
+
AlertDialogAction,
|
|
12
|
+
AlertDialogCancel,
|
|
13
|
+
AlertDialogContent,
|
|
14
|
+
AlertDialogDescription,
|
|
15
|
+
AlertDialogFooter,
|
|
16
|
+
AlertDialogHeader,
|
|
17
|
+
AlertDialogTitle,
|
|
18
|
+
} from '../../../ui/alert-dialog'
|
|
19
|
+
import { authClient } from '../../../../lib/auth/client'
|
|
20
|
+
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuSeparator } from '../../../ui/dropdown-menu'
|
|
21
|
+
import RevokeAllSessionsButton from './revoke-all-sessions'
|
|
22
|
+
|
|
23
|
+
type Target = { id: string; email: string; role: string; banned: boolean }
|
|
24
|
+
|
|
25
|
+
async function call(url: string, init: RequestInit, fallback: string) {
|
|
26
|
+
const res = await fetch(url, init)
|
|
27
|
+
if (!res.ok) throw new Error((await res.json().catch(() => ({}))).error || fallback)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Button + confirmation dialog. `children` lets the dialog carry extra input (ban reason).
|
|
31
|
+
function Confirm({
|
|
32
|
+
label, title, description, confirmLabel = 'Confirm', variant = 'outline', onConfirm, children,
|
|
33
|
+
}: {
|
|
34
|
+
label: string
|
|
35
|
+
title: string
|
|
36
|
+
description: string
|
|
37
|
+
confirmLabel?: string
|
|
38
|
+
variant?: 'outline' | 'destructive'
|
|
39
|
+
onConfirm: () => Promise<void>
|
|
40
|
+
children?: ReactNode
|
|
41
|
+
}) {
|
|
42
|
+
const [open, setOpen] = useState(false)
|
|
43
|
+
const [busy, setBusy] = useState(false)
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<Button variant={variant} size="sm" onClick={() => setOpen(true)}>{label}</Button>
|
|
47
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
48
|
+
<AlertDialogContent>
|
|
49
|
+
<AlertDialogHeader>
|
|
50
|
+
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
51
|
+
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
52
|
+
</AlertDialogHeader>
|
|
53
|
+
{children}
|
|
54
|
+
<AlertDialogFooter>
|
|
55
|
+
<AlertDialogCancel disabled={busy}>Cancel</AlertDialogCancel>
|
|
56
|
+
<AlertDialogAction
|
|
57
|
+
disabled={busy}
|
|
58
|
+
className={variant === 'destructive' ? 'bg-destructive hover:bg-destructive/90' : ''}
|
|
59
|
+
onClick={async (e) => {
|
|
60
|
+
e.preventDefault()
|
|
61
|
+
setBusy(true)
|
|
62
|
+
try {
|
|
63
|
+
await onConfirm()
|
|
64
|
+
setOpen(false)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
toast.error(err instanceof Error ? err.message : 'Action failed')
|
|
67
|
+
} finally {
|
|
68
|
+
setBusy(false)
|
|
69
|
+
}
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
{busy ? 'Processing...' : confirmLabel}
|
|
73
|
+
</AlertDialogAction>
|
|
74
|
+
</AlertDialogFooter>
|
|
75
|
+
</AlertDialogContent>
|
|
76
|
+
</AlertDialog>
|
|
77
|
+
</>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const EXPORT_SECTIONS = [
|
|
82
|
+
['profile', 'Profile'],
|
|
83
|
+
['security', 'Security'],
|
|
84
|
+
['logins', 'Registration & Login Info'],
|
|
85
|
+
['devices', 'Devices'],
|
|
86
|
+
['consent', 'Consent'],
|
|
87
|
+
['activity', 'Activity Log'],
|
|
88
|
+
] as const
|
|
89
|
+
|
|
90
|
+
// Pick which sections go into the profile CSV, then download it.
|
|
91
|
+
function ExportMenu({ userId }: { userId: string }) {
|
|
92
|
+
const [picked, setPicked] = useState<string[]>(EXPORT_SECTIONS.map(([k]) => k))
|
|
93
|
+
const toggle = (k: string, on: boolean) => setPicked((p) => (on ? [...p, k] : p.filter((x) => x !== k)))
|
|
94
|
+
return (
|
|
95
|
+
<DropdownMenu>
|
|
96
|
+
<DropdownMenuTrigger asChild>
|
|
97
|
+
<Button variant="outline" size="sm">Export CSV</Button>
|
|
98
|
+
</DropdownMenuTrigger>
|
|
99
|
+
<DropdownMenuContent align="end">
|
|
100
|
+
{EXPORT_SECTIONS.map(([key, label]) => (
|
|
101
|
+
<DropdownMenuCheckboxItem
|
|
102
|
+
key={key}
|
|
103
|
+
checked={picked.includes(key)}
|
|
104
|
+
onCheckedChange={(on) => toggle(key, on)}
|
|
105
|
+
onSelect={(e) => e.preventDefault()}
|
|
106
|
+
>
|
|
107
|
+
{label}
|
|
108
|
+
</DropdownMenuCheckboxItem>
|
|
109
|
+
))}
|
|
110
|
+
<DropdownMenuSeparator />
|
|
111
|
+
<div className="p-1">
|
|
112
|
+
<Button size="sm" className="w-full" disabled={picked.length === 0} asChild={picked.length > 0}>
|
|
113
|
+
{picked.length > 0 ? (
|
|
114
|
+
<a href={`/api/admin/users/${userId}/export?sections=${picked.join(',')}`} download>Download</a>
|
|
115
|
+
) : 'Download'}
|
|
116
|
+
</Button>
|
|
117
|
+
</div>
|
|
118
|
+
</DropdownMenuContent>
|
|
119
|
+
</DropdownMenu>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Page-header toolbar: impersonate, role, password reset email, delete.
|
|
124
|
+
export function AdminUserHeaderActions({ user, isSelf }: { user: Target; isSelf: boolean }) {
|
|
125
|
+
const router = useRouter()
|
|
126
|
+
|
|
127
|
+
const changeRole = async (role: string) => {
|
|
128
|
+
try {
|
|
129
|
+
await call(`/api/admin/users/${user.id}/role`, {
|
|
130
|
+
method: 'PATCH',
|
|
131
|
+
headers: { 'Content-Type': 'application/json' },
|
|
132
|
+
body: JSON.stringify({ role }),
|
|
133
|
+
}, 'Failed to update role')
|
|
134
|
+
toast.success(`Role changed to ${role}`)
|
|
135
|
+
router.refresh()
|
|
136
|
+
} catch (err) {
|
|
137
|
+
toast.error(err instanceof Error ? err.message : 'Failed to update role')
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
143
|
+
<Select value={user.role} onValueChange={changeRole} disabled={isSelf}>
|
|
144
|
+
<SelectTrigger className="h-8 w-[110px]" aria-label="Role"><SelectValue /></SelectTrigger>
|
|
145
|
+
<SelectContent>
|
|
146
|
+
<SelectItem value="user">User</SelectItem>
|
|
147
|
+
<SelectItem value="tester">Tester</SelectItem>
|
|
148
|
+
<SelectItem value="admin">Admin</SelectItem>
|
|
149
|
+
</SelectContent>
|
|
150
|
+
</Select>
|
|
151
|
+
|
|
152
|
+
<ExportMenu userId={user.id} />
|
|
153
|
+
|
|
154
|
+
<Button
|
|
155
|
+
variant="outline"
|
|
156
|
+
size="sm"
|
|
157
|
+
onClick={async () => {
|
|
158
|
+
const { error } = await authClient.requestPasswordReset({ email: user.email, redirectTo: '/reset-password' })
|
|
159
|
+
if (error) toast.error(error.message || 'Could not send reset email')
|
|
160
|
+
else toast.success(`Password reset email sent to ${user.email}`)
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
Send password reset
|
|
164
|
+
</Button>
|
|
165
|
+
|
|
166
|
+
{!isSelf && !user.banned && (
|
|
167
|
+
<Confirm
|
|
168
|
+
label="Impersonate"
|
|
169
|
+
title="Impersonate User?"
|
|
170
|
+
description="You'll be signed in as this user until you stop impersonating. This is logged."
|
|
171
|
+
onConfirm={async () => {
|
|
172
|
+
const { error } = await authClient.admin.impersonateUser({ userId: user.id })
|
|
173
|
+
if (error) throw new Error(error.message || 'Failed to impersonate user')
|
|
174
|
+
router.push('/dashboard')
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
{!isSelf && (
|
|
180
|
+
<Confirm
|
|
181
|
+
label="Delete"
|
|
182
|
+
variant="destructive"
|
|
183
|
+
title="Delete User?"
|
|
184
|
+
description="This action will permanently delete the user and all their data."
|
|
185
|
+
onConfirm={async () => {
|
|
186
|
+
await call(`/api/admin/users/${user.id}`, { method: 'DELETE' }, 'Failed to delete user')
|
|
187
|
+
toast.success('User deleted')
|
|
188
|
+
router.push('/dashboard/admin/users')
|
|
189
|
+
router.refresh()
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Sidebar danger zone: ban / unban and revoke every session.
|
|
198
|
+
export function AdminUserDangerZone({ user, isSelf }: { user: Target; isSelf: boolean }) {
|
|
199
|
+
const router = useRouter()
|
|
200
|
+
const [reason, setReason] = useState('')
|
|
201
|
+
|
|
202
|
+
const setBan = async (ban: boolean) => {
|
|
203
|
+
await call(`/api/admin/users/${user.id}/ban`, {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
headers: { 'Content-Type': 'application/json' },
|
|
206
|
+
body: JSON.stringify(ban ? { ban, reason: reason.trim() || 'Banned by admin' } : { ban }),
|
|
207
|
+
}, `Failed to ${ban ? 'ban' : 'unban'} user`)
|
|
208
|
+
toast.success(ban ? 'User banned' : 'User unbanned')
|
|
209
|
+
setReason('')
|
|
210
|
+
router.refresh()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (isSelf) return <p className="text-sm text-muted-foreground">You can't use these actions on your own account.</p>
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<div className="flex flex-wrap gap-2">
|
|
217
|
+
{user.banned ? (
|
|
218
|
+
<Confirm label="Unban account" title="Unban User?" description="This will restore the user's access." onConfirm={() => setBan(false)} />
|
|
219
|
+
) : (
|
|
220
|
+
<Confirm
|
|
221
|
+
label="Ban account"
|
|
222
|
+
title="Ban User?"
|
|
223
|
+
description="This will revoke all sessions and prevent the user from logging in."
|
|
224
|
+
variant="destructive"
|
|
225
|
+
onConfirm={() => setBan(true)}
|
|
226
|
+
>
|
|
227
|
+
<Input
|
|
228
|
+
placeholder="Reason (optional, shown to the user)"
|
|
229
|
+
value={reason}
|
|
230
|
+
onChange={(e) => setReason(e.target.value)}
|
|
231
|
+
maxLength={500}
|
|
232
|
+
/>
|
|
233
|
+
</Confirm>
|
|
234
|
+
)}
|
|
235
|
+
<RevokeAllSessionsButton userId={user.id} variant="outline" />
|
|
236
|
+
</div>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../../../ui/card"
|
|
2
|
+
import { Avatar, AvatarFallback, AvatarImage } from "../../../ui/avatar"
|
|
3
|
+
import { Badge } from "../../../ui/badge"
|
|
4
|
+
import { Separator } from "../../../ui/separator"
|
|
5
|
+
import { formatDate, getUserInitials } from "../../../../lib/utils/formatters"
|
|
6
|
+
import VerifyEmailButton from "../../common/verify-email-button"
|
|
7
|
+
|
|
8
|
+
type User = {
|
|
9
|
+
id: string
|
|
10
|
+
name: string
|
|
11
|
+
email: string
|
|
12
|
+
image?: string | null
|
|
13
|
+
emailVerified: boolean
|
|
14
|
+
role: string | null | undefined
|
|
15
|
+
createdAt: Date
|
|
16
|
+
updatedAt: Date
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// One identity card instead of the old Profile + Account Details pair, which
|
|
20
|
+
// repeated email and role.
|
|
21
|
+
export default function AdminUserProfileCard({ user }: { user: User }) {
|
|
22
|
+
return (
|
|
23
|
+
<Card>
|
|
24
|
+
<CardHeader>
|
|
25
|
+
<CardTitle>Profile</CardTitle>
|
|
26
|
+
</CardHeader>
|
|
27
|
+
<CardContent className="space-y-4">
|
|
28
|
+
<div className="flex items-center gap-4">
|
|
29
|
+
<Avatar className="h-16 w-16">
|
|
30
|
+
<AvatarImage src={user.image || undefined} alt={user.name} />
|
|
31
|
+
<AvatarFallback className="text-xl">{getUserInitials(user.name)}</AvatarFallback>
|
|
32
|
+
</Avatar>
|
|
33
|
+
<div className="min-w-0">
|
|
34
|
+
<div className="flex items-center gap-2">
|
|
35
|
+
<h3 className="truncate text-lg font-semibold">{user.name}</h3>
|
|
36
|
+
<Badge variant={user.role === 'admin' ? 'default' : 'secondary'} className="capitalize">{user.role || 'user'}</Badge>
|
|
37
|
+
</div>
|
|
38
|
+
<p className="truncate text-sm text-muted-foreground">{user.email}</p>
|
|
39
|
+
<p className="truncate font-mono text-xs text-muted-foreground">{user.id}</p>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<Separator />
|
|
44
|
+
|
|
45
|
+
<div>
|
|
46
|
+
<p className="text-sm font-medium text-gray-600">Email</p>
|
|
47
|
+
<div className="mt-1 flex flex-wrap items-center gap-2">
|
|
48
|
+
<Badge variant={user.emailVerified ? 'default' : 'destructive'}>
|
|
49
|
+
{user.emailVerified ? 'Verified' : 'Unverified'}
|
|
50
|
+
</Badge>
|
|
51
|
+
{!user.emailVerified && <VerifyEmailButton email={user.email} />}
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<Separator />
|
|
56
|
+
|
|
57
|
+
<div className="grid grid-cols-2 gap-4">
|
|
58
|
+
<div>
|
|
59
|
+
<p className="text-sm font-medium text-gray-600">Member Since</p>
|
|
60
|
+
<p className="text-base">{formatDate(user.createdAt)}</p>
|
|
61
|
+
</div>
|
|
62
|
+
<div>
|
|
63
|
+
<p className="text-sm font-medium text-gray-600">Last Updated</p>
|
|
64
|
+
<p className="text-base">{formatDate(user.updatedAt)}</p>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</CardContent>
|
|
68
|
+
</Card>
|
|
69
|
+
)
|
|
70
|
+
}
|