@xk2800/nextjs-template 0.7.2-beta.2 → 0.7.2-beta.4

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 (212) hide show
  1. package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
  2. package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
  3. package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +8 -8
  4. package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
  5. package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
  6. package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
  7. package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
  8. package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
  9. package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
  10. package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
  11. package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
  12. package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
  13. package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
  14. package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
  15. package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
  16. package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
  17. package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
  18. package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
  19. package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
  20. package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
  21. package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
  22. package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
  23. package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
  24. package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
  25. package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
  26. package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
  27. package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
  28. package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
  29. package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
  30. package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
  31. package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
  32. package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
  33. package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
  34. package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
  35. package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
  36. package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
  37. package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
  38. package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
  39. package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
  40. package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
  41. package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
  42. package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
  43. package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
  44. package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
  45. package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
  46. package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
  47. package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
  48. package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
  49. package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
  50. package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
  51. package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
  52. package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
  53. package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
  54. package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
  55. package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
  56. package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
  57. package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
  58. package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +4 -6
  59. package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
  60. package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
  61. package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
  62. package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +5 -5
  63. package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
  64. package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
  65. package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +5 -5
  66. package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
  67. package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
  68. package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
  69. package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
  70. package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
  71. package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
  72. package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
  73. package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
  74. package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
  75. package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
  76. package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
  77. package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
  78. package/components/email/team/workspace-invite.tsx +51 -0
  79. package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
  80. package/components/error-boundary.tsx +32 -0
  81. package/components/settings/appearance/appearance-section.tsx +64 -0
  82. package/components/settings/index.ts +5 -0
  83. package/components/settings/notifications/notifications-section.tsx +31 -0
  84. package/components/settings/profile/profile-section.tsx +38 -0
  85. package/components/settings/security/security-section.tsx +24 -0
  86. package/components/settings/settings-nav.tsx +35 -0
  87. package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
  88. package/components/site/push/push-notifications-card.tsx +117 -0
  89. package/components/ui/collapsible.tsx +9 -0
  90. package/components/ui/column-picker.tsx +1 -1
  91. package/components/ui/data-table.tsx +1 -1
  92. package/components/ui/tabs.tsx +52 -0
  93. package/dist/activity/logger.js +2 -2
  94. package/dist/activity/logger.js.map +1 -1
  95. package/dist/activity/logger.mjs +3 -3
  96. package/dist/activity/queries.d.mts +7 -3
  97. package/dist/activity/queries.d.ts +7 -3
  98. package/dist/activity/queries.js +16 -5
  99. package/dist/activity/queries.js.map +1 -1
  100. package/dist/activity/queries.mjs +18 -7
  101. package/dist/activity/queries.mjs.map +1 -1
  102. package/dist/admin/queries.js +4 -4
  103. package/dist/admin/queries.js.map +1 -1
  104. package/dist/admin/queries.mjs +5 -5
  105. package/dist/admin/queries.mjs.map +1 -1
  106. package/dist/api/feedback.js +25 -24
  107. package/dist/api/feedback.js.map +1 -1
  108. package/dist/api/feedback.mjs +8 -8
  109. package/dist/api/feedback.mjs.map +1 -1
  110. package/dist/api/marketing.js +28 -27
  111. package/dist/api/marketing.js.map +1 -1
  112. package/dist/api/marketing.mjs +12 -12
  113. package/dist/api/marketing.mjs.map +1 -1
  114. package/dist/auth/helpers.d.mts +22 -22
  115. package/dist/auth/helpers.d.ts +22 -22
  116. package/dist/auth/helpers.js +26 -25
  117. package/dist/auth/helpers.js.map +1 -1
  118. package/dist/auth/helpers.mjs +8 -8
  119. package/dist/auth/index.js +24 -23
  120. package/dist/auth/index.js.map +1 -1
  121. package/dist/auth/index.mjs +7 -7
  122. package/dist/auth-client/index.js +1 -1
  123. package/dist/auth-client/index.js.map +1 -1
  124. package/dist/auth-client/index.mjs.map +1 -1
  125. package/dist/{chunk-VVXYKVFJ.mjs → chunk-2BKXG4MG.mjs} +8 -7
  126. package/dist/chunk-2BKXG4MG.mjs.map +1 -0
  127. package/dist/{chunk-653GF7OT.mjs → chunk-AOSJUQQG.mjs} +4 -4
  128. package/dist/chunk-AOSJUQQG.mjs.map +1 -0
  129. package/dist/{chunk-L242CZ64.mjs → chunk-CRDC62BU.mjs} +2 -2
  130. package/dist/chunk-CRDC62BU.mjs.map +1 -0
  131. package/dist/{chunk-NQELV53D.mjs → chunk-J5XRJ2GW.mjs} +3 -3
  132. package/dist/chunk-J5XRJ2GW.mjs.map +1 -0
  133. package/dist/{chunk-6OAHCEDJ.mjs → chunk-JRDMU6I2.mjs} +4 -4
  134. package/dist/chunk-JRDMU6I2.mjs.map +1 -0
  135. package/dist/{chunk-O5EQYHNC.mjs → chunk-JSB36AY6.mjs} +4 -4
  136. package/dist/chunk-JSB36AY6.mjs.map +1 -0
  137. package/dist/{chunk-TE5BEAQB.mjs → chunk-M6Y2XNJC.mjs} +3 -3
  138. package/dist/chunk-M6Y2XNJC.mjs.map +1 -0
  139. package/dist/{chunk-K2GCSLRJ.mjs → chunk-NOFQCVHC.mjs} +14 -13
  140. package/dist/chunk-NOFQCVHC.mjs.map +1 -0
  141. package/dist/{chunk-K62JYJRR.mjs → chunk-RLZ7F7ZY.mjs} +3 -3
  142. package/dist/{chunk-K62JYJRR.mjs.map → chunk-RLZ7F7ZY.mjs.map} +1 -1
  143. package/dist/{chunk-2BJ3B4FR.mjs → chunk-TMANA7KL.mjs} +41 -5
  144. package/dist/chunk-TMANA7KL.mjs.map +1 -0
  145. package/dist/db/index.js +1 -1
  146. package/dist/db/index.js.map +1 -1
  147. package/dist/db/index.mjs +2 -2
  148. package/dist/db/schema.js +1 -1
  149. package/dist/db/schema.js.map +1 -1
  150. package/dist/db/schema.mjs +1 -1
  151. package/dist/errors.js +2 -2
  152. package/dist/errors.js.map +1 -1
  153. package/dist/errors.mjs +3 -3
  154. package/dist/marketing/index.js +2 -2
  155. package/dist/marketing/index.js.map +1 -1
  156. package/dist/marketing/index.mjs +2 -2
  157. package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
  158. package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
  159. package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
  160. package/dist/reset-password-64VQEXBW.mjs.map +1 -0
  161. package/dist/sessions/queries.js +1 -1
  162. package/dist/sessions/queries.js.map +1 -1
  163. package/dist/sessions/queries.mjs +2 -2
  164. package/dist/sessions/queries.mjs.map +1 -1
  165. package/dist/settings/queries.d.mts +9 -1
  166. package/dist/settings/queries.d.ts +9 -1
  167. package/dist/settings/queries.js +38 -1
  168. package/dist/settings/queries.js.map +1 -1
  169. package/dist/settings/queries.mjs +3 -3
  170. package/dist/users/queries.d.mts +18 -3
  171. package/dist/users/queries.d.ts +18 -3
  172. package/dist/users/queries.js +70 -11
  173. package/dist/users/queries.js.map +1 -1
  174. package/dist/users/queries.mjs +53 -15
  175. package/dist/users/queries.mjs.map +1 -1
  176. package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
  177. package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
  178. package/lib/push/client.ts +39 -0
  179. package/lib/security/activity-severity.ts +57 -0
  180. package/package.json +113 -18
  181. package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
  182. package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
  183. package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
  184. package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
  185. package/dist/chunk-653GF7OT.mjs.map +0 -1
  186. package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
  187. package/dist/chunk-K2GCSLRJ.mjs.map +0 -1
  188. package/dist/chunk-L242CZ64.mjs.map +0 -1
  189. package/dist/chunk-NQELV53D.mjs.map +0 -1
  190. package/dist/chunk-O5EQYHNC.mjs.map +0 -1
  191. package/dist/chunk-TE5BEAQB.mjs.map +0 -1
  192. package/dist/chunk-VVXYKVFJ.mjs.map +0 -1
  193. package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
  194. package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
  195. package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
  196. /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
  197. /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
  198. /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
  199. /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
  200. /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
  201. /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
  202. /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
  203. /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
  204. /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
  205. /package/lib/{auth-client.ts → auth/client.ts} +0 -0
  206. /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
  207. /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
  208. /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
  209. /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
  210. /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
  211. /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
  212. /package/lib/{request-info.ts → utils/request-info.ts} +0 -0
@@ -0,0 +1,255 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useEffect, useRef, useState } from 'react'
4
+ import Link from 'next/link'
5
+ import { RefreshCw } from 'lucide-react'
6
+ import { toast } from 'sonner'
7
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../../../ui/card'
8
+ import { Button } from '../../../ui/button'
9
+ import { Input } from '../../../ui/input'
10
+ import { Badge } from '../../../ui/badge'
11
+ import { Skeleton } from '../../../ui/skeleton'
12
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../../ui/select'
13
+ import { DataTable, DataTablePagination, type Column } from '../../../ui/data-table'
14
+ import {
15
+ AlertDialog,
16
+ AlertDialogAction,
17
+ AlertDialogCancel,
18
+ AlertDialogContent,
19
+ AlertDialogDescription,
20
+ AlertDialogFooter,
21
+ AlertDialogHeader,
22
+ AlertDialogTitle,
23
+ } from '../../../ui/alert-dialog'
24
+ import { formatDateTime } from '../../../../lib/utils/formatters'
25
+
26
+ interface Row {
27
+ id: string
28
+ status: 'active' | 'ended' | 'revoked'
29
+ adminId: string
30
+ adminName: string | null
31
+ adminEmail: string | null
32
+ targetId: string | null
33
+ targetName: string | null
34
+ targetEmail: string | null
35
+ startedAt: string
36
+ endedAt: string | null
37
+ ipAddress: string | null
38
+ userAgent: string | null
39
+ }
40
+
41
+ interface Stats { active: number; last24h: number; uniqueAdmins: number }
42
+ interface Data { sessions: Row[]; total: number; pages: number; stats: Stats }
43
+
44
+ function duration(row: Row) {
45
+ if (!row.endedAt && row.status !== 'active') return '—'
46
+ const ms = (row.endedAt ? new Date(row.endedAt).getTime() : Date.now()) - new Date(row.startedAt).getTime()
47
+ const s = Math.max(0, Math.floor(ms / 1000))
48
+ const p = (n: number) => String(n).padStart(2, '0')
49
+ return `${p(Math.floor(s / 3600))}:${p(Math.floor((s % 3600) / 60))}:${p(s % 60)}`
50
+ }
51
+
52
+ function StatusBadge({ status }: { status: Row['status'] }) {
53
+ if (status === 'active') {
54
+ return (
55
+ <Badge className="gap-1.5 border-transparent bg-emerald-100 text-emerald-900 dark:bg-emerald-500/15 dark:text-emerald-300">
56
+ <span className="relative flex size-2">
57
+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-emerald-500 opacity-75" />
58
+ <span className="relative inline-flex size-2 rounded-full bg-emerald-500" />
59
+ </span>
60
+ Active now
61
+ </Badge>
62
+ )
63
+ }
64
+ return status === 'revoked'
65
+ ? <Badge variant="destructive">Revoked</Badge>
66
+ : <Badge variant="secondary">Ended</Badge>
67
+ }
68
+
69
+ function Person({ id, name, email }: { id: string | null; name: string | null; email: string | null }) {
70
+ if (!id || (!name && !email)) return <span className="text-sm text-muted-foreground">Deleted account</span>
71
+ return (
72
+ <div className="text-sm">
73
+ <Link href={`/dashboard/admin/users/${id}`} className="font-medium hover:underline">{name || email}</Link>
74
+ {name && <div className="text-xs text-gray-500">{email}</div>}
75
+ </div>
76
+ )
77
+ }
78
+
79
+ // Full impersonation history: stats, searchable/filterable table, and an
80
+ // End session action for live sessions. Data comes from /api/admin/users/impersonation.
81
+ export default function ImpersonationTab() {
82
+ const [data, setData] = useState<Data | null>(null)
83
+ const [loading, setLoading] = useState(true)
84
+ const [search, setSearch] = useState('')
85
+ const [status, setStatus] = useState('all')
86
+ const [page, setPage] = useState(1)
87
+ const [ending, setEnding] = useState<Row | null>(null)
88
+ const [busy, setBusy] = useState(false)
89
+ const requestId = useRef(0)
90
+
91
+ const load = useCallback(async (silent = false) => {
92
+ const id = ++requestId.current
93
+ if (!silent) setLoading(true)
94
+ try {
95
+ const res = await fetch(`/api/admin/users/impersonation?${new URLSearchParams({ search, status, page: String(page) })}`)
96
+ if (!res.ok) throw new Error()
97
+ const json = await res.json()
98
+ if (id === requestId.current) setData(json)
99
+ } catch {
100
+ if (!silent && id === requestId.current) toast.error('Failed to load impersonation sessions')
101
+ } finally {
102
+ if (id === requestId.current) setLoading(false)
103
+ }
104
+ }, [search, status, page])
105
+
106
+ // Debounced reload on filter change (also covers first load).
107
+ useEffect(() => {
108
+ const t = setTimeout(() => load(), 250)
109
+ return () => clearTimeout(t)
110
+ }, [load])
111
+
112
+ // Keep durations and active state fresh while the tab is open.
113
+ useEffect(() => {
114
+ const t = setInterval(() => load(true), 15_000)
115
+ return () => clearInterval(t)
116
+ }, [load])
117
+
118
+ const endSession = async () => {
119
+ if (!ending) return
120
+ setBusy(true)
121
+ try {
122
+ const res = await fetch('/api/admin/users/impersonation/end', {
123
+ method: 'POST',
124
+ headers: { 'Content-Type': 'application/json' },
125
+ body: JSON.stringify({ adminId: ending.adminId, targetId: ending.targetId }),
126
+ })
127
+ if (!res.ok) throw new Error((await res.json().catch(() => ({}))).error || 'Failed to end session')
128
+ toast.success('Impersonation session ended')
129
+ setEnding(null)
130
+ load(true)
131
+ } catch (err) {
132
+ toast.error(err instanceof Error ? err.message : 'Failed to end session')
133
+ } finally {
134
+ setBusy(false)
135
+ }
136
+ }
137
+
138
+ const columns: Column<Row>[] = [
139
+ { name: 'status', title: 'Status', sticky: true, minWidth: 130, renderer: (r) => <StatusBadge status={r.status} /> },
140
+ { name: 'admin', title: 'Admin', minWidth: 200, renderer: (r) => <Person id={r.adminId} name={r.adminName} email={r.adminEmail} /> },
141
+ { name: 'target', title: 'Target account', minWidth: 200, renderer: (r) => <Person id={r.targetId} name={r.targetName} email={r.targetEmail} /> },
142
+ { name: 'startedAt', title: 'Started', renderer: (r) => <span className="text-sm text-gray-600 dark:text-gray-400">{formatDateTime(r.startedAt)}</span> },
143
+ { name: 'duration', title: 'Duration', renderer: (r) => <span className="font-mono text-sm">{duration(r)}</span> },
144
+ {
145
+ name: 'ip',
146
+ title: 'IP',
147
+ renderer: (r) => (
148
+ <span className="font-mono text-sm" title={r.userAgent ?? undefined}>{r.ipAddress || '—'}</span>
149
+ ),
150
+ },
151
+ {
152
+ name: 'actions',
153
+ title: '',
154
+ minWidth: 100,
155
+ renderer: (r) =>
156
+ r.status === 'active' ? (
157
+ <Button variant="destructive" size="sm" onClick={() => setEnding(r)}>End session</Button>
158
+ ) : null,
159
+ },
160
+ ]
161
+
162
+ const stats = data?.stats
163
+ const tiles = [
164
+ { label: 'Active now', value: stats?.active, pulse: !!stats?.active },
165
+ { label: 'Started in last 24h', value: stats?.last24h },
166
+ { label: 'Unique admins', value: stats?.uniqueAdmins },
167
+ ]
168
+
169
+ return (
170
+ <div className="space-y-6">
171
+ <div className="grid gap-4 sm:grid-cols-3">
172
+ {tiles.map((t) => (
173
+ <Card key={t.label}>
174
+ <CardHeader className="pb-2">
175
+ <CardDescription className="flex items-center gap-2">
176
+ {t.pulse && (
177
+ <span className="relative flex size-2">
178
+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-emerald-500 opacity-75" />
179
+ <span className="relative inline-flex size-2 rounded-full bg-emerald-500" />
180
+ </span>
181
+ )}
182
+ {t.label}
183
+ </CardDescription>
184
+ <CardTitle className="text-3xl">{t.value ?? '—'}</CardTitle>
185
+ </CardHeader>
186
+ </Card>
187
+ ))}
188
+ </div>
189
+
190
+ <Card>
191
+ <CardHeader className="space-y-4">
192
+ <div>
193
+ <CardTitle>Impersonation audit feed</CardTitle>
194
+ <CardDescription>
195
+ {data ? `${data.total} impersonation session${data.total === 1 ? '' : 's'}` : 'Loading...'}
196
+ </CardDescription>
197
+ </div>
198
+ <div className="flex flex-wrap items-center gap-2">
199
+ <Input
200
+ placeholder="Search admin or target..."
201
+ value={search}
202
+ onChange={(e) => { setSearch(e.target.value); setPage(1) }}
203
+ className="max-w-xs"
204
+ />
205
+ <Select value={status} onValueChange={(v) => { setStatus(v); setPage(1) }}>
206
+ <SelectTrigger className="w-[150px]"><SelectValue /></SelectTrigger>
207
+ <SelectContent>
208
+ <SelectItem value="all">Status: All</SelectItem>
209
+ <SelectItem value="active">Active</SelectItem>
210
+ <SelectItem value="ended">Ended</SelectItem>
211
+ <SelectItem value="revoked">Revoked</SelectItem>
212
+ </SelectContent>
213
+ </Select>
214
+ <Button variant="outline" size="sm" className="ml-auto" disabled={loading} onClick={() => load()}>
215
+ <RefreshCw className={loading ? 'animate-spin' : undefined} /> Refresh
216
+ </Button>
217
+ </div>
218
+ </CardHeader>
219
+ <CardContent>
220
+ {loading && !data ? (
221
+ <div className="space-y-4">{[...Array(4)].map((_, i) => <Skeleton key={i} className="h-14 w-full" />)}</div>
222
+ ) : !data || data.sessions.length === 0 ? (
223
+ <p className="py-8 text-center text-gray-500">No impersonation sessions found</p>
224
+ ) : (
225
+ <DataTable columns={columns} data={data.sessions} getRowId={(r) => r.id} pageSize={false} />
226
+ )}
227
+ {data && (
228
+ <DataTablePagination page={page} pages={data.pages} onPageChange={setPage} className="mt-6 pt-6" />
229
+ )}
230
+ </CardContent>
231
+ </Card>
232
+
233
+ <AlertDialog open={!!ending} onOpenChange={(o) => !o && setEnding(null)}>
234
+ <AlertDialogContent>
235
+ <AlertDialogHeader>
236
+ <AlertDialogTitle>End impersonation session?</AlertDialogTitle>
237
+ <AlertDialogDescription>
238
+ {ending?.adminEmail ?? 'The admin'} will be signed out of {ending?.targetEmail ?? 'the target account'} immediately. This is logged.
239
+ </AlertDialogDescription>
240
+ </AlertDialogHeader>
241
+ <AlertDialogFooter>
242
+ <AlertDialogCancel disabled={busy}>Cancel</AlertDialogCancel>
243
+ <AlertDialogAction
244
+ disabled={busy}
245
+ className="bg-destructive hover:bg-destructive/90"
246
+ onClick={(e) => { e.preventDefault(); endSession() }}
247
+ >
248
+ {busy ? 'Ending...' : 'End session'}
249
+ </AlertDialogAction>
250
+ </AlertDialogFooter>
251
+ </AlertDialogContent>
252
+ </AlertDialog>
253
+ </div>
254
+ )
255
+ }
@@ -0,0 +1,80 @@
1
+ 'use client'
2
+
3
+ import { useState } from 'react'
4
+ import { toast } from 'sonner'
5
+ import { UserPlus } from 'lucide-react'
6
+ import { Button } from '../../../ui/button'
7
+ import { Input } from '../../../ui/input'
8
+ import { Label } from '../../../ui/label'
9
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../../ui/select'
10
+ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '../../../ui/dialog'
11
+
12
+ export default function InviteUserDialog({ onInvited }: { onInvited?: () => void }) {
13
+ const [open, setOpen] = useState(false)
14
+ const [email, setEmail] = useState('')
15
+ const [name, setName] = useState('')
16
+ const [role, setRole] = useState('user')
17
+ const [busy, setBusy] = useState(false)
18
+
19
+ async function submit(e: React.FormEvent) {
20
+ e.preventDefault()
21
+ setBusy(true)
22
+ try {
23
+ const res = await fetch('/api/admin/users/invite', {
24
+ method: 'POST',
25
+ headers: { 'Content-Type': 'application/json' },
26
+ body: JSON.stringify({ email, name, role }),
27
+ })
28
+ const data = await res.json().catch(() => ({}))
29
+ if (!res.ok) throw new Error(data.error || 'Failed to invite user')
30
+ toast.success(`Invite sent to ${email}`)
31
+ setOpen(false)
32
+ setEmail('')
33
+ setName('')
34
+ setRole('user')
35
+ onInvited?.()
36
+ } catch (err) {
37
+ toast.error(err instanceof Error ? err.message : 'Failed to invite user')
38
+ } finally {
39
+ setBusy(false)
40
+ }
41
+ }
42
+
43
+ return (
44
+ <Dialog open={open} onOpenChange={setOpen}>
45
+ <DialogTrigger asChild>
46
+ <Button size="sm"><UserPlus /> Invite user</Button>
47
+ </DialogTrigger>
48
+ <DialogContent>
49
+ <form onSubmit={submit} className="space-y-4">
50
+ <DialogHeader>
51
+ <DialogTitle>Invite user</DialogTitle>
52
+ <DialogDescription>Creates the account and emails a link to set a password (valid 7 days). They can also sign in with a social provider using the same email.</DialogDescription>
53
+ </DialogHeader>
54
+ <div className="space-y-2">
55
+ <Label htmlFor="invite-email">Email</Label>
56
+ <Input id="invite-email" type="email" required value={email} onChange={(e) => setEmail(e.target.value)} />
57
+ </div>
58
+ <div className="space-y-2">
59
+ <Label htmlFor="invite-name">Name (optional)</Label>
60
+ <Input id="invite-name" value={name} onChange={(e) => setName(e.target.value)} />
61
+ </div>
62
+ <div className="space-y-2">
63
+ <Label>Role</Label>
64
+ <Select value={role} onValueChange={setRole}>
65
+ <SelectTrigger><SelectValue /></SelectTrigger>
66
+ <SelectContent>
67
+ <SelectItem value="user">User</SelectItem>
68
+ <SelectItem value="tester">Tester</SelectItem>
69
+ <SelectItem value="admin">Admin</SelectItem>
70
+ </SelectContent>
71
+ </Select>
72
+ </div>
73
+ <DialogFooter>
74
+ <Button type="submit" disabled={busy}>{busy ? 'Sending...' : 'Send invite'}</Button>
75
+ </DialogFooter>
76
+ </form>
77
+ </DialogContent>
78
+ </Dialog>
79
+ )
80
+ }
@@ -3,7 +3,7 @@
3
3
  import { useState } from "react"
4
4
  import { useRouter } from "next/navigation"
5
5
  import { toast } from "sonner"
6
- import { Button } from "../../ui/button"
6
+ import { Button } from "../../../ui/button"
7
7
  import {
8
8
  AlertDialog,
9
9
  AlertDialogAction,
@@ -13,7 +13,7 @@ import {
13
13
  AlertDialogFooter,
14
14
  AlertDialogHeader,
15
15
  AlertDialogTitle,
16
- } from "../../ui/alert-dialog"
16
+ } from "../../../ui/alert-dialog"
17
17
 
18
18
  // Kills every session for one account — the fast path when a new-device alert
19
19
  // turns out to be a hijack. Hits the existing admin route with no sessionId,
@@ -22,10 +22,12 @@ export default function RevokeAllSessionsButton({
22
22
  userId,
23
23
  label = "Revoke all sessions",
24
24
  size = "sm",
25
+ variant = "destructive",
25
26
  }: {
26
27
  userId: string
27
28
  label?: string
28
29
  size?: "sm" | "default"
30
+ variant?: "destructive" | "outline"
29
31
  }) {
30
32
  const router = useRouter()
31
33
  const [open, setOpen] = useState(false)
@@ -48,7 +50,7 @@ export default function RevokeAllSessionsButton({
48
50
 
49
51
  return (
50
52
  <>
51
- <Button variant="destructive" size={size} onClick={() => setOpen(true)}>
53
+ <Button variant={variant} size={size} onClick={() => setOpen(true)}>
52
54
  {label}
53
55
  </Button>
54
56
  <AlertDialog open={open} onOpenChange={setOpen}>
@@ -1,5 +1,5 @@
1
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../../ui/card"
2
- import { Skeleton } from "../../ui/skeleton"
1
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../../../../ui/card"
2
+ import { Skeleton } from "../../../../ui/skeleton"
3
3
 
4
4
  export default function AdminUsersSkeleton() {
5
5
  return (
@@ -1,5 +1,5 @@
1
1
  import { getUsersFiltered } from "@xk2800/nextjs-template/users/queries"
2
- import AdminUsersTable from "./adminUsersTable"
2
+ import AdminUsersTable from "./admin-users-table"
3
3
 
4
4
  export default async function UsersSection() {
5
5
  const { users, total, page, limit, pages } = await getUsersFiltered({ page: 1, limit: 10 })
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useEffect, useState, useSyncExternalStore } from "react"
4
4
  import { toast, type ExternalToast } from "sonner"
5
- import FeedbackDialog from "./feedbackDialog"
5
+ import FeedbackDialog from "./feedback-dialog"
6
6
 
7
7
  // One hidden feedback dialog for reporting errors. Mount <ErrorFeedbackHost />
8
8
  // once in a layout, only when feedback is configured (FEEDBACK_DISCORD_WEBHOOK_URL
@@ -4,9 +4,9 @@ import { useState } from "react"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { toast } from "sonner"
6
6
  import { MessageSquare } from "lucide-react"
7
- import { Button } from "../ui/button"
8
- import { Label } from "../ui/label"
9
- import { Textarea } from "../ui/textarea"
7
+ import { Button } from "../../ui/button"
8
+ import { Label } from "../../ui/label"
9
+ import { Textarea } from "../../ui/textarea"
10
10
  import {
11
11
  Dialog,
12
12
  DialogContent,
@@ -15,7 +15,7 @@ import {
15
15
  DialogHeader,
16
16
  DialogTitle,
17
17
  DialogTrigger,
18
- } from "../ui/dialog"
18
+ } from "../../ui/dialog"
19
19
 
20
20
  // Keep in sync with the cap in app/api/feedback/route.ts.
21
21
  const FEEDBACK_MAX_LENGTH = 2000
@@ -1,5 +1,5 @@
1
1
  import { AlertTriangle } from "lucide-react"
2
- import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"
2
+ import { Card, CardContent, CardHeader, CardTitle } from "../../ui/card"
3
3
 
4
4
  export default function SectionErrorFallback({ title }: { title: string }) {
5
5
  return (
@@ -2,8 +2,8 @@
2
2
 
3
3
  import { useState } from 'react'
4
4
  import { toast } from 'sonner'
5
- import { Button } from '../ui/button'
6
- import { authClient } from '../../lib/auth-client'
5
+ import { Button } from '../../ui/button'
6
+ import { authClient } from '../../../lib/auth/client'
7
7
 
8
8
  export default function VerifyEmailButton({ email }: { email: string }) {
9
9
  const [sending, setSending] = useState(false)
@@ -9,11 +9,10 @@ import {
9
9
  Users,
10
10
  ScrollText,
11
11
  SlidersHorizontal,
12
- Table,
13
12
  LogOut,
14
13
  } from "lucide-react"
15
14
 
16
- import { authClient } from "../../lib/auth-client"
15
+ import { authClient } from "../../../lib/auth/client"
17
16
  import {
18
17
  Sidebar,
19
18
  SidebarContent,
@@ -25,9 +24,9 @@ import {
25
24
  SidebarMenu,
26
25
  SidebarMenuButton,
27
26
  SidebarMenuItem,
28
- } from "../ui/sidebar"
29
- import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"
30
- import { Button } from "../ui/button"
27
+ } from "../../ui/sidebar"
28
+ import { Avatar, AvatarFallback, AvatarImage } from "../../ui/avatar"
29
+ import { Button } from "../../ui/button"
31
30
 
32
31
  export interface AppSidebarUser {
33
32
  name: string
@@ -44,7 +43,6 @@ export interface AppSidebarProps {
44
43
 
45
44
  export const workspaceLinks = [
46
45
  { href: "/dashboard", label: "Overview", icon: LayoutDashboard },
47
- { href: "/dashboard/data-table", label: "DataTable", icon: Table },
48
46
  { href: "/dashboard/settings", label: "Settings", icon: Settings },
49
47
  ]
50
48
 
@@ -1,5 +1,5 @@
1
1
  import Link from "next/link"
2
- import LogoutButtons from "../auth/logoutButtons"
2
+ import LogoutButtons from "../../auth/session/logout-buttons"
3
3
 
4
4
  export interface DashboardNavLink {
5
5
  href: string
@@ -3,8 +3,8 @@
3
3
  import { useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
5
  import { toast } from 'sonner'
6
- import { authClient, useSession } from '../../lib/auth-client'
7
- import { Button } from '../ui/button'
6
+ import { authClient, useSession } from '../../../lib/auth/client'
7
+ import { Button } from '../../ui/button'
8
8
 
9
9
  // Shown app-wide (see app/dashboard/layout.tsx) while the current session is
10
10
  // an admin impersonating another user, so it's impossible to forget you're
@@ -3,7 +3,7 @@
3
3
  import { useRouter } from "next/navigation"
4
4
  import { PanelLeft, PanelTop } from "lucide-react"
5
5
 
6
- import { Button } from "../ui/button"
6
+ import { Button } from "../../ui/button"
7
7
 
8
8
  export type NavStyle = "sidebar" | "topbar"
9
9
 
@@ -4,11 +4,11 @@ import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { ArrowLeft, LogOut } from "lucide-react"
6
6
 
7
- import { authClient } from "../../lib/auth-client"
8
- import { cn } from "../../lib/utils"
9
- import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"
10
- import { Button } from "../ui/button"
11
- import { adminLinks, workspaceLinks, type AppSidebarProps } from "./appSidebar"
7
+ import { authClient } from "../../../lib/auth/client"
8
+ import { cn } from "../../../lib/utils"
9
+ import { Avatar, AvatarFallback, AvatarImage } from "../../ui/avatar"
10
+ import { Button } from "../../ui/button"
11
+ import { adminLinks, workspaceLinks, type AppSidebarProps } from "./app-sidebar"
12
12
 
13
13
  export default function TopNav({
14
14
  user,
@@ -2,8 +2,8 @@
2
2
 
3
3
  import { useEffect, useState, type ReactNode } from 'react'
4
4
  import { CircleCheck, Download } from 'lucide-react'
5
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../ui/card'
6
- import { Button } from '../ui/button'
5
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../ui/card'
6
+ import { Button } from '../../ui/button'
7
7
 
8
8
  // Chrome/Edge's install event; not in the DOM typings yet.
9
9
  type InstallPromptEvent = Event & { prompt: () => Promise<{ outcome: 'accepted' | 'dismissed' }> }
@@ -1,8 +1,8 @@
1
- import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"
2
- import { Badge } from "../ui/badge"
3
- import { Separator } from "../ui/separator"
4
- import { formatDate } from "../../lib/formatters"
5
- import VerifyEmailButton from "./verifyEmailButton"
1
+ import { Card, CardContent, CardHeader, CardTitle } from "../../ui/card"
2
+ import { Badge } from "../../ui/badge"
3
+ import { Separator } from "../../ui/separator"
4
+ import { formatDate } from "../../../lib/utils/formatters"
5
+ import VerifyEmailButton from "../common/verify-email-button"
6
6
 
7
7
  type User = {
8
8
  id: string
@@ -1,11 +1,11 @@
1
1
  'use client'
2
2
 
3
3
  import { useEffect, useState } from 'react'
4
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../ui/card'
5
- import { Badge } from '../ui/badge'
6
- import { Skeleton } from '../ui/skeleton'
7
- import { DataTable, type Column } from '../ui/data-table'
8
- import { formatDateTime, actionBadgeVariant } from '../../lib/formatters'
4
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../ui/card'
5
+ import { Badge } from '../../ui/badge'
6
+ import { Skeleton } from '../../ui/skeleton'
7
+ import { DataTable, type Column } from '../../ui/data-table'
8
+ import { formatDateTime, actionBadgeVariant } from '../../../lib/utils/formatters'
9
9
 
10
10
  interface ActivityLog {
11
11
  id: string
@@ -1,5 +1,5 @@
1
1
  import { getUserActivityLogs, getAllActivityLogs } from "@xk2800/nextjs-template/activity/queries"
2
- import ActivityLogsCard from "./activityLogsCard"
2
+ import ActivityLogsCard from "./activity-logs-card"
3
3
 
4
4
  export default async function ActivityLogsSection({
5
5
  userId,
@@ -1,7 +1,7 @@
1
1
  import Link from "next/link"
2
2
  import { ShieldCheck, LayoutDashboard } from "lucide-react"
3
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../ui/card"
4
- import { Button } from "../ui/button"
3
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../../ui/card"
4
+ import { Button } from "../../ui/button"
5
5
 
6
6
  export default function AdminSection() {
7
7
  return (
@@ -2,10 +2,10 @@
2
2
 
3
3
  import { useEffect, useState } from 'react'
4
4
  import { toast } from 'sonner'
5
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../ui/card'
6
- import { Button } from '../ui/button'
7
- import { Input } from '../ui/input'
8
- import { PasswordInput } from '../ui/password-input'
5
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../ui/card'
6
+ import { Button } from '../../ui/button'
7
+ import { Input } from '../../ui/input'
8
+ import { PasswordInput } from '../../ui/password-input'
9
9
  import {
10
10
  AlertDialog,
11
11
  AlertDialogCancel,
@@ -14,9 +14,9 @@ import {
14
14
  AlertDialogFooter,
15
15
  AlertDialogHeader,
16
16
  AlertDialogTitle,
17
- } from '../ui/alert-dialog'
18
- import { authClient, useSession } from '../../lib/auth-client'
19
- import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'
17
+ } from '../../ui/alert-dialog'
18
+ import { authClient, useSession } from '../../../lib/auth/client'
19
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip'
20
20
 
21
21
  type Props = {
22
22
  /**
@@ -2,9 +2,9 @@
2
2
 
3
3
  import { useState } from "react"
4
4
  import { toast } from "sonner"
5
- import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../ui/card"
6
- import { Switch } from "../ui/switch"
7
- import { Label } from "../ui/label"
5
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "../../ui/card"
6
+ import { Switch } from "../../ui/switch"
7
+ import { Label } from "../../ui/label"
8
8
 
9
9
  export default function MarketingUpdatesCard({
10
10
  initialSubscribed,
@@ -1,5 +1,5 @@
1
1
  import { isSubscribed, MARKETING_SEGMENT_ID } from "@xk2800/nextjs-template/marketing"
2
- import MarketingUpdatesCard from "./marketingUpdatesCard"
2
+ import MarketingUpdatesCard from "./marketing-updates-card"
3
3
 
4
4
  // Dashboard opt-in for product updates. Renders nothing until
5
5
  // RESEND_MARKETING_SEGMENT_ID is set.