@xk2800/nextjs-template 0.7.2-beta.0 → 0.7.2-beta.10

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 (248) hide show
  1. package/README.md +1 -0
  2. package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
  3. package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
  4. package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
  5. package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
  6. package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
  7. package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
  8. package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
  9. package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
  10. package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
  11. package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
  12. package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
  13. package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
  14. package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
  15. package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
  16. package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
  17. package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
  18. package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
  19. package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
  20. package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
  21. package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
  22. package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
  23. package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
  24. package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
  25. package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
  26. package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
  27. package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
  28. package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
  29. package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
  30. package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
  31. package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
  32. package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
  33. package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
  34. package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
  35. package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
  36. package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
  37. package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
  38. package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
  39. package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
  40. package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
  41. package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
  42. package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
  43. package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
  44. package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
  45. package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
  46. package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
  47. package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
  48. package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
  49. package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
  50. package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
  51. package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
  52. package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
  53. package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
  54. package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
  55. package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
  56. package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
  57. package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
  58. package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
  59. package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
  60. package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
  61. package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
  62. package/components/dashboard/layout/mobile-nav.tsx +95 -0
  63. package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
  64. package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
  65. package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
  66. package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
  67. package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
  68. package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
  69. package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
  70. package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
  71. package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
  72. package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
  73. package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
  74. package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
  75. package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
  76. package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
  77. package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
  78. package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
  79. package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
  80. package/components/email/team/workspace-invite.tsx +51 -0
  81. package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
  82. package/components/error-boundary.tsx +32 -0
  83. package/components/settings/appearance/appearance-section.tsx +64 -0
  84. package/components/settings/index.ts +5 -0
  85. package/components/settings/notifications/notifications-section.tsx +31 -0
  86. package/components/settings/profile/profile-section.tsx +38 -0
  87. package/components/settings/security/security-section.tsx +24 -0
  88. package/components/settings/settings-nav.tsx +35 -0
  89. package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
  90. package/components/site/push/push-notifications-card.tsx +117 -0
  91. package/components/ui/collapsible.tsx +9 -0
  92. package/components/ui/column-picker.tsx +1 -1
  93. package/components/ui/data-table.tsx +1 -1
  94. package/components/ui/dialog.tsx +46 -13
  95. package/components/ui/drawer.tsx +88 -0
  96. package/components/ui/tabs.tsx +52 -0
  97. package/dist/activity/logger.d.mts +2 -1
  98. package/dist/activity/logger.d.ts +2 -1
  99. package/dist/activity/logger.js +66 -16
  100. package/dist/activity/logger.js.map +1 -1
  101. package/dist/activity/logger.mjs +4 -4
  102. package/dist/activity/queries.d.mts +32 -21
  103. package/dist/activity/queries.d.ts +32 -21
  104. package/dist/activity/queries.js +86 -23
  105. package/dist/activity/queries.js.map +1 -1
  106. package/dist/activity/queries.mjs +27 -14
  107. package/dist/activity/queries.mjs.map +1 -1
  108. package/dist/admin/queries.d.mts +2 -1
  109. package/dist/admin/queries.d.ts +2 -1
  110. package/dist/admin/queries.js +48 -18
  111. package/dist/admin/queries.js.map +1 -1
  112. package/dist/admin/queries.mjs +9 -9
  113. package/dist/admin/queries.mjs.map +1 -1
  114. package/dist/api/feedback.js +284 -249
  115. package/dist/api/feedback.js.map +1 -1
  116. package/dist/api/feedback.mjs +14 -12
  117. package/dist/api/feedback.mjs.map +1 -1
  118. package/dist/api/marketing.js +302 -267
  119. package/dist/api/marketing.js.map +1 -1
  120. package/dist/api/marketing.mjs +16 -25
  121. package/dist/api/marketing.mjs.map +1 -1
  122. package/dist/auth/helpers.d.mts +63 -21
  123. package/dist/auth/helpers.d.ts +63 -21
  124. package/dist/auth/helpers.js +314 -268
  125. package/dist/auth/helpers.js.map +1 -1
  126. package/dist/auth/helpers.mjs +9 -9
  127. package/dist/auth/index.d.mts +86 -47
  128. package/dist/auth/index.d.ts +86 -47
  129. package/dist/auth/index.js +278 -245
  130. package/dist/auth/index.js.map +1 -1
  131. package/dist/auth/index.mjs +8 -8
  132. package/dist/auth-client/index.d.mts +1214 -2526
  133. package/dist/auth-client/index.d.ts +1214 -2526
  134. package/dist/auth-client/index.js +37 -3
  135. package/dist/auth-client/index.js.map +1 -1
  136. package/dist/auth-client/index.mjs +19 -3
  137. package/dist/auth-client/index.mjs.map +1 -1
  138. package/dist/{chunk-KA2KMGPY.mjs → chunk-3BH6BVBQ.mjs} +17 -8
  139. package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
  140. package/dist/chunk-D56ENLSX.mjs +6 -0
  141. package/dist/chunk-D56ENLSX.mjs.map +1 -0
  142. package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
  143. package/dist/chunk-DCPVEZS7.mjs.map +1 -0
  144. package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
  145. package/dist/chunk-DWLMCMXF.mjs.map +1 -0
  146. package/dist/{chunk-YH53UPUW.mjs → chunk-EXMUANQ3.mjs} +4 -4
  147. package/dist/chunk-EXMUANQ3.mjs.map +1 -0
  148. package/dist/{chunk-VHNGYAIG.mjs → chunk-IH6CMZIN.mjs} +213 -220
  149. package/dist/chunk-IH6CMZIN.mjs.map +1 -0
  150. package/dist/chunk-LADVCLEQ.mjs +43 -0
  151. package/dist/chunk-LADVCLEQ.mjs.map +1 -0
  152. package/dist/{chunk-A6JXMHOQ.mjs → chunk-NJBRKKLK.mjs} +46 -7
  153. package/dist/chunk-NJBRKKLK.mjs.map +1 -0
  154. package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
  155. package/dist/chunk-QDUPSU5O.mjs.map +1 -0
  156. package/dist/{chunk-JUSU6UZA.mjs → chunk-S23GC776.mjs} +41 -29
  157. package/dist/chunk-S23GC776.mjs.map +1 -0
  158. package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
  159. package/dist/chunk-TIR7KHXL.mjs.map +1 -0
  160. package/dist/{chunk-4F6KE47S.mjs → chunk-ZOQHHFYA.mjs} +7 -4
  161. package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
  162. package/dist/config/env.d.mts +3 -0
  163. package/dist/config/env.d.ts +3 -0
  164. package/dist/config/env.js +12 -2
  165. package/dist/config/env.js.map +1 -1
  166. package/dist/config/env.mjs +1 -1
  167. package/dist/db/index.d.mts +3 -7
  168. package/dist/db/index.d.ts +3 -7
  169. package/dist/db/index.js +61 -13
  170. package/dist/db/index.js.map +1 -1
  171. package/dist/db/index.mjs +3 -3
  172. package/dist/db/schema.d.mts +1 -1
  173. package/dist/db/schema.d.ts +1 -1
  174. package/dist/db/schema.js +14 -5
  175. package/dist/db/schema.js.map +1 -1
  176. package/dist/db/schema.mjs +1 -1
  177. package/dist/errors.d.mts +2 -1
  178. package/dist/errors.d.ts +2 -1
  179. package/dist/errors.js +62 -14
  180. package/dist/errors.js.map +1 -1
  181. package/dist/errors.mjs +4 -4
  182. package/dist/marketing/index.d.mts +4 -3
  183. package/dist/marketing/index.d.ts +4 -3
  184. package/dist/marketing/index.js +14 -4
  185. package/dist/marketing/index.js.map +1 -1
  186. package/dist/marketing/index.mjs +3 -3
  187. package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
  188. package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
  189. package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
  190. package/dist/reset-password-64VQEXBW.mjs.map +1 -0
  191. package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
  192. package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
  193. package/dist/sessions/queries.js +61 -13
  194. package/dist/sessions/queries.js.map +1 -1
  195. package/dist/sessions/queries.mjs +3 -3
  196. package/dist/sessions/queries.mjs.map +1 -1
  197. package/dist/settings/queries.d.mts +11 -2
  198. package/dist/settings/queries.d.ts +11 -2
  199. package/dist/settings/queries.js +84 -14
  200. package/dist/settings/queries.js.map +1 -1
  201. package/dist/settings/queries.mjs +4 -4
  202. package/dist/users/queries.d.mts +41 -21
  203. package/dist/users/queries.d.ts +41 -21
  204. package/dist/users/queries.js +117 -24
  205. package/dist/users/queries.js.map +1 -1
  206. package/dist/users/queries.mjs +57 -17
  207. package/dist/users/queries.mjs.map +1 -1
  208. package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
  209. package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
  210. package/lib/{auth-client.ts → auth/client.ts} +22 -2
  211. package/lib/{maintenance.ts → config/maintenance.ts} +0 -1
  212. package/lib/push/client.ts +39 -0
  213. package/lib/security/activity-severity.ts +57 -0
  214. package/lib/{request-info.ts → utils/request-info.ts} +7 -3
  215. package/package.json +177 -75
  216. package/scripts/check-deps.mjs +68 -0
  217. package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
  218. package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
  219. package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
  220. package/dist/chunk-4C7JHGT5.mjs +0 -30
  221. package/dist/chunk-4C7JHGT5.mjs.map +0 -1
  222. package/dist/chunk-4F6KE47S.mjs.map +0 -1
  223. package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
  224. package/dist/chunk-A6JXMHOQ.mjs.map +0 -1
  225. package/dist/chunk-HUEDEAY3.mjs.map +0 -1
  226. package/dist/chunk-JUSU6UZA.mjs.map +0 -1
  227. package/dist/chunk-KA2KMGPY.mjs.map +0 -1
  228. package/dist/chunk-L242CZ64.mjs.map +0 -1
  229. package/dist/chunk-NQELV53D.mjs.map +0 -1
  230. package/dist/chunk-VHNGYAIG.mjs.map +0 -1
  231. package/dist/chunk-YH53UPUW.mjs.map +0 -1
  232. package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
  233. package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
  234. package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
  235. /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
  236. /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
  237. /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
  238. /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
  239. /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
  240. /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
  241. /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
  242. /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
  243. /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
  244. /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
  245. /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
  246. /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
  247. /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
  248. /package/lib/{recalculate-columns.ts → utils/recalculate-columns.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 | null
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
@@ -35,16 +34,19 @@ export interface AppSidebarUser {
35
34
  image?: string | null
36
35
  }
37
36
 
37
+ export type NavLink = { href: string; label: string; icon: React.ComponentType<{ className?: string }> }
38
+
38
39
  export interface AppSidebarProps {
39
40
  user: AppSidebarUser
40
41
  isAdmin: boolean
42
+ /** Workspace links. Defaults to Overview and Settings (`workspaceLinks`). The admin links are unaffected. */
43
+ links?: NavLink[]
41
44
  brandName?: React.ReactNode
42
45
  brandHref?: string
43
46
  }
44
47
 
45
- export const workspaceLinks = [
48
+ export const workspaceLinks: NavLink[] = [
46
49
  { href: "/dashboard", label: "Overview", icon: LayoutDashboard },
47
- { href: "/dashboard/data-table", label: "DataTable", icon: Table },
48
50
  { href: "/dashboard/settings", label: "Settings", icon: Settings },
49
51
  ]
50
52
 
@@ -69,6 +71,7 @@ export default function AppSidebar({
69
71
  isAdmin,
70
72
  brandName = "Template",
71
73
  brandHref = "/",
74
+ links = workspaceLinks,
72
75
  }: AppSidebarProps) {
73
76
  const pathname = usePathname()
74
77
 
@@ -101,7 +104,7 @@ export default function AppSidebar({
101
104
  <SidebarGroupLabel>Workspace</SidebarGroupLabel>
102
105
  <SidebarGroupContent>
103
106
  <SidebarMenu>
104
- {workspaceLinks.map((link) => (
107
+ {links.map((link) => (
105
108
  <SidebarMenuItem key={link.href}>
106
109
  <SidebarMenuButton
107
110
  asChild
@@ -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
@@ -0,0 +1,95 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { usePathname } from "next/navigation"
5
+ import { ArrowLeft } from "lucide-react"
6
+
7
+ import { cn } from "../../../lib/utils"
8
+ import { adminLinks, workspaceLinks, type NavLink } from "./app-sidebar"
9
+
10
+ /** "tabs": plain bar fixed to the bottom edge. "dock": floating rounded bar, with an optional raised centre button. "off": no bottom bar. */
11
+ export type MobileNavVariant = "tabs" | "dock" | "off"
12
+
13
+ /** The dock's centre button, e.g. `{ href: "/dashboard/scan", label: "Scan", icon: <ScanLine /> }`. */
14
+ export type MobileNavAction = {
15
+ href: string
16
+ label: string
17
+ icon: React.ReactNode
18
+ }
19
+
20
+ /** Bottom navigation below `md`. Inside /dashboard/admin it switches to the admin links plus an Exit tab. */
21
+ export default function MobileNav({
22
+ isAdmin,
23
+ variant = "tabs",
24
+ action,
25
+ links = workspaceLinks,
26
+ }: {
27
+ isAdmin: boolean
28
+ /** Workspace tabs. Defaults to Overview and Settings. */
29
+ links?: NavLink[]
30
+ variant?: MobileNavVariant
31
+ action?: MobileNavAction
32
+ }) {
33
+ const pathname = usePathname()
34
+ const inAdmin = isAdmin && pathname.startsWith("/dashboard/admin")
35
+ const tabs = inAdmin
36
+ ? [...adminLinks, { href: "/dashboard", label: "Exit", icon: ArrowLeft, exit: true }]
37
+ : isAdmin
38
+ ? [...links, { ...adminLinks[0], label: "Admin" }]
39
+ : links
40
+ const tabActive = (href: string, exit?: boolean) =>
41
+ !exit &&
42
+ (href === "/dashboard" || href === adminLinks[0].href
43
+ ? pathname === href
44
+ : pathname.startsWith(href))
45
+ const dock = variant === "dock"
46
+ if (variant === "off") return null
47
+
48
+ const renderTab = ({ href, label, icon: Icon, ...rest }: (typeof tabs)[number]) => {
49
+ const active = tabActive(href, "exit" in rest)
50
+ return (
51
+ <Link
52
+ key={href}
53
+ href={href}
54
+ aria-current={active ? "page" : undefined}
55
+ className={cn(
56
+ "flex min-w-0 flex-1 flex-col items-center justify-start gap-0.5 px-1 text-center leading-tight text-muted-foreground",
57
+ dock ? "gap-1 py-2.5 text-xs" : "py-2 text-[11px]",
58
+ active && "font-medium text-foreground"
59
+ )}
60
+ >
61
+ <Icon className={dock ? "size-6" : "size-5"} />
62
+ <span className="w-full truncate text-center">{label}</span>
63
+ </Link>
64
+ )
65
+ }
66
+
67
+ // The centre button sits in the middle, so split the tabs around it (extra tab goes left).
68
+ const half = Math.ceil(tabs.length / 2)
69
+ const centre = dock && action && (
70
+ <Link
71
+ key="action"
72
+ href={action.href}
73
+ aria-label={action.label}
74
+ className="mx-1 flex size-14 shrink-0 items-center justify-center self-center rounded-2xl bg-primary text-primary-foreground shadow-sm transition-transform active:scale-95 [&_svg]:size-6"
75
+ >
76
+ {action.icon}
77
+ </Link>
78
+ )
79
+
80
+ return (
81
+ <nav
82
+ aria-label="Primary"
83
+ className={cn(
84
+ "fixed z-20 flex md:hidden",
85
+ dock
86
+ ? "inset-x-3 bottom-[calc(0.75rem+env(safe-area-inset-bottom))] items-stretch rounded-3xl border bg-background/95 px-2 py-1 shadow-lg backdrop-blur supports-[backdrop-filter]:bg-background/80"
87
+ : "inset-x-0 bottom-0 border-t bg-background pb-[env(safe-area-inset-bottom)]"
88
+ )}
89
+ >
90
+ {centre
91
+ ? [...tabs.slice(0, half).map(renderTab), centre, ...tabs.slice(half).map(renderTab)]
92
+ : tabs.map(renderTab)}
93
+ </nav>
94
+ )
95
+ }
@@ -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