@xk2800/nextjs-template 0.7.2-beta.3 → 0.7.2-beta.5

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 (213) 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/dialog.tsx +46 -13
  93. package/components/ui/tabs.tsx +52 -0
  94. package/dist/activity/logger.js +2 -2
  95. package/dist/activity/logger.js.map +1 -1
  96. package/dist/activity/logger.mjs +3 -3
  97. package/dist/activity/queries.d.mts +7 -3
  98. package/dist/activity/queries.d.ts +7 -3
  99. package/dist/activity/queries.js +16 -5
  100. package/dist/activity/queries.js.map +1 -1
  101. package/dist/activity/queries.mjs +18 -7
  102. package/dist/activity/queries.mjs.map +1 -1
  103. package/dist/admin/queries.js +4 -4
  104. package/dist/admin/queries.js.map +1 -1
  105. package/dist/admin/queries.mjs +5 -5
  106. package/dist/admin/queries.mjs.map +1 -1
  107. package/dist/api/feedback.js +24 -24
  108. package/dist/api/feedback.js.map +1 -1
  109. package/dist/api/feedback.mjs +8 -8
  110. package/dist/api/feedback.mjs.map +1 -1
  111. package/dist/api/marketing.js +27 -27
  112. package/dist/api/marketing.js.map +1 -1
  113. package/dist/api/marketing.mjs +12 -12
  114. package/dist/api/marketing.mjs.map +1 -1
  115. package/dist/auth/helpers.d.mts +22 -22
  116. package/dist/auth/helpers.d.ts +22 -22
  117. package/dist/auth/helpers.js +25 -25
  118. package/dist/auth/helpers.js.map +1 -1
  119. package/dist/auth/helpers.mjs +8 -8
  120. package/dist/auth/index.js +23 -23
  121. package/dist/auth/index.js.map +1 -1
  122. package/dist/auth/index.mjs +7 -7
  123. package/dist/auth-client/index.js +1 -1
  124. package/dist/auth-client/index.js.map +1 -1
  125. package/dist/auth-client/index.mjs.map +1 -1
  126. package/dist/{chunk-YHQ4A5RF.mjs → chunk-2BKXG4MG.mjs} +8 -7
  127. package/dist/chunk-2BKXG4MG.mjs.map +1 -0
  128. package/dist/{chunk-653GF7OT.mjs → chunk-AOSJUQQG.mjs} +4 -4
  129. package/dist/chunk-AOSJUQQG.mjs.map +1 -0
  130. package/dist/{chunk-L242CZ64.mjs → chunk-CRDC62BU.mjs} +2 -2
  131. package/dist/chunk-CRDC62BU.mjs.map +1 -0
  132. package/dist/{chunk-NQELV53D.mjs → chunk-J5XRJ2GW.mjs} +3 -3
  133. package/dist/chunk-J5XRJ2GW.mjs.map +1 -0
  134. package/dist/{chunk-6OAHCEDJ.mjs → chunk-JRDMU6I2.mjs} +4 -4
  135. package/dist/chunk-JRDMU6I2.mjs.map +1 -0
  136. package/dist/{chunk-O5EQYHNC.mjs → chunk-JSB36AY6.mjs} +4 -4
  137. package/dist/chunk-JSB36AY6.mjs.map +1 -0
  138. package/dist/{chunk-TE5BEAQB.mjs → chunk-M6Y2XNJC.mjs} +3 -3
  139. package/dist/chunk-M6Y2XNJC.mjs.map +1 -0
  140. package/dist/{chunk-ONJDPUVO.mjs → chunk-NOFQCVHC.mjs} +13 -13
  141. package/dist/chunk-NOFQCVHC.mjs.map +1 -0
  142. package/dist/{chunk-K62JYJRR.mjs → chunk-RLZ7F7ZY.mjs} +3 -3
  143. package/dist/{chunk-K62JYJRR.mjs.map → chunk-RLZ7F7ZY.mjs.map} +1 -1
  144. package/dist/{chunk-2BJ3B4FR.mjs → chunk-TMANA7KL.mjs} +41 -5
  145. package/dist/chunk-TMANA7KL.mjs.map +1 -0
  146. package/dist/db/index.js +1 -1
  147. package/dist/db/index.js.map +1 -1
  148. package/dist/db/index.mjs +2 -2
  149. package/dist/db/schema.js +1 -1
  150. package/dist/db/schema.js.map +1 -1
  151. package/dist/db/schema.mjs +1 -1
  152. package/dist/errors.js +2 -2
  153. package/dist/errors.js.map +1 -1
  154. package/dist/errors.mjs +3 -3
  155. package/dist/marketing/index.js +2 -2
  156. package/dist/marketing/index.js.map +1 -1
  157. package/dist/marketing/index.mjs +2 -2
  158. package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
  159. package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
  160. package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
  161. package/dist/reset-password-64VQEXBW.mjs.map +1 -0
  162. package/dist/sessions/queries.js +1 -1
  163. package/dist/sessions/queries.js.map +1 -1
  164. package/dist/sessions/queries.mjs +2 -2
  165. package/dist/sessions/queries.mjs.map +1 -1
  166. package/dist/settings/queries.d.mts +9 -1
  167. package/dist/settings/queries.d.ts +9 -1
  168. package/dist/settings/queries.js +38 -1
  169. package/dist/settings/queries.js.map +1 -1
  170. package/dist/settings/queries.mjs +3 -3
  171. package/dist/users/queries.d.mts +18 -3
  172. package/dist/users/queries.d.ts +18 -3
  173. package/dist/users/queries.js +70 -11
  174. package/dist/users/queries.js.map +1 -1
  175. package/dist/users/queries.mjs +53 -15
  176. package/dist/users/queries.mjs.map +1 -1
  177. package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
  178. package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
  179. package/lib/push/client.ts +39 -0
  180. package/lib/security/activity-severity.ts +57 -0
  181. package/package.json +114 -18
  182. package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
  183. package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
  184. package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
  185. package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
  186. package/dist/chunk-653GF7OT.mjs.map +0 -1
  187. package/dist/chunk-6OAHCEDJ.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-ONJDPUVO.mjs.map +0 -1
  192. package/dist/chunk-TE5BEAQB.mjs.map +0 -1
  193. package/dist/chunk-YHQ4A5RF.mjs.map +0 -1
  194. package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
  195. package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
  196. package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
  197. /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
  198. /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
  199. /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
  200. /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
  201. /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
  202. /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
  203. /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
  204. /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
  205. /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
  206. /package/lib/{auth-client.ts → auth/client.ts} +0 -0
  207. /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
  208. /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
  209. /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
  210. /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
  211. /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
  212. /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
  213. /package/lib/{request-info.ts → utils/request-info.ts} +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useEffect, useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
- import { authClient } from '../../lib/auth-client'
5
+ import { authClient } from '../../../lib/auth/client'
6
6
 
7
7
  type Props = {
8
8
  /** The `?error=` code better-auth redirected to /login with. */
@@ -4,14 +4,14 @@ import React, { useEffect, useState } from 'react'
4
4
  import Link from 'next/link'
5
5
  import { useRouter } from 'next/navigation'
6
6
  import { z } from 'zod'
7
- import { Button } from '../ui/button'
8
- import { Input } from '../ui/input'
9
- import { PasswordInput } from '../ui/password-input'
10
- import { Label } from '../ui/label'
11
- import { authClient } from '../../lib/auth-client'
12
- import { getVisitorId } from '../../lib/device-fingerprint'
13
- import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../lib/cookie-names'
14
- import { LoginSchema } from '../../types/auth/loginSchema'
7
+ import { Button } from '../../ui/button'
8
+ import { Input } from '../../ui/input'
9
+ import { PasswordInput } from '../../ui/password-input'
10
+ import { Label } from '../../ui/label'
11
+ import { authClient } from '../../../lib/auth/client'
12
+ import { getVisitorId } from '../../../lib/security/device-fingerprint'
13
+ import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../../lib/security/cookie-names'
14
+ import { LoginSchema } from '../../../types/auth/loginSchema'
15
15
  import { toast } from 'sonner'
16
16
 
17
17
  type Props = {
@@ -2,14 +2,14 @@
2
2
 
3
3
  import React, { useEffect, useMemo, useState } from 'react'
4
4
  import { z } from 'zod'
5
- import { Button } from '../ui/button'
6
- import { Input } from '../ui/input'
7
- import { PasswordInput } from '../ui/password-input'
8
- import { Label } from '../ui/label'
9
- import { authClient } from '../../lib/auth-client'
10
- import { getVisitorId } from '../../lib/device-fingerprint'
11
- import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../lib/cookie-names'
12
- import { SignupSchema } from '../../types/auth/signupSchema'
5
+ import { Button } from '../../ui/button'
6
+ import { Input } from '../../ui/input'
7
+ import { PasswordInput } from '../../ui/password-input'
8
+ import { Label } from '../../ui/label'
9
+ import { authClient } from '../../../lib/auth/client'
10
+ import { getVisitorId } from '../../../lib/security/device-fingerprint'
11
+ import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../../lib/security/cookie-names'
12
+ import { SignupSchema } from '../../../types/auth/signupSchema'
13
13
  import { toast } from 'sonner'
14
14
 
15
15
  type Props = {
@@ -1,9 +1,9 @@
1
1
  import Link from 'next/link'
2
- import { Separator } from "../ui/separator"
3
- import SocialLogin from './socialLogin'
4
- import EmailPasswordLogin from './emailPasswordLogin'
5
- import EmailPasswordSignup from './emailPasswordSignup'
6
- import PasskeyLogin from './passkeyLogin'
2
+ import { Separator } from "../../ui/separator"
3
+ import SocialLogin from '../methods/social-login'
4
+ import EmailPasswordLogin from '../forms/login-form'
5
+ import EmailPasswordSignup from '../forms/signup-form'
6
+ import PasskeyLogin from '../methods/passkey-login'
7
7
 
8
8
  type Props = {
9
9
  authCardTitle: string
@@ -1,21 +1,33 @@
1
1
  import type { ReactNode } from "react"
2
2
  import { Check } from "lucide-react"
3
3
 
4
- import { Logo } from "@/components/site/logo"
5
- import { ThemeToggle } from "@/components/theme/theme-toggle"
4
+ import Link from "next/link"
5
+
6
+ import { ThemeToggle } from "../../theme/theme-toggle"
7
+
8
+ // Neutral default so the package works out of the box; pass `logo` to brand it.
9
+ const DefaultLogo = () => (
10
+ <Link href="/" className="flex items-center gap-2 font-semibold">
11
+ <span className="flex size-6 items-center justify-center rounded-md bg-foreground text-background text-sm font-bold">
12
+ N
13
+ </span>
14
+ nextjs-template
15
+ </Link>
16
+ )
6
17
 
7
18
  type Props = {
8
19
  headline: string
9
20
  bullets: string[]
10
21
  children: ReactNode
22
+ logo?: ReactNode
11
23
  }
12
24
 
13
- export function AuthShell({ headline, bullets, children }: Props) {
25
+ export function AuthShell({ headline, bullets, children, logo = <DefaultLogo /> }: Props) {
14
26
  return (
15
27
  <div className="grid min-h-screen lg:grid-cols-2">
16
28
  <div className="relative hidden flex-col justify-center border-r border-border/60 bg-secondary/30 p-10 lg:flex">
17
29
  <div className="absolute top-10 left-10">
18
- <Logo />
30
+ {logo}
19
31
  </div>
20
32
  <div>
21
33
  <h1 className="text-3xl font-bold tracking-tight text-balance">{headline}</h1>
@@ -33,7 +45,7 @@ export function AuthShell({ headline, bullets, children }: Props) {
33
45
  <div className="flex flex-col p-6 sm:p-10">
34
46
  <div className="flex items-center justify-between lg:justify-end">
35
47
  <div className="lg:hidden">
36
- <Logo />
48
+ {logo}
37
49
  </div>
38
50
  <ThemeToggle />
39
51
  </div>
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
 
3
- import { authClient, useSession } from '../../lib/auth-client'
4
- import { useConsentFor } from '../../lib/cookie-consent'
3
+ import { authClient, useSession } from '../../../lib/auth/client'
4
+ import { useConsentFor } from '../../../lib/security/cookie-consent'
5
5
  import { useRouter } from 'next/navigation'
6
6
  import React, { useEffect, useRef, useState } from 'react'
7
7
 
@@ -3,8 +3,8 @@
3
3
  import React, { useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
5
  import { KeyRound } from 'lucide-react'
6
- import { Button } from '../ui/button'
7
- import { authClient } from '../../lib/auth-client'
6
+ import { Button } from '../../ui/button'
7
+ import { authClient } from '../../../lib/auth/client'
8
8
  import { toast } from 'sonner'
9
9
 
10
10
  type Props = {
@@ -1,10 +1,10 @@
1
1
  'use client'
2
2
 
3
- import { Button } from '../ui/button'
3
+ import { Button } from '../../ui/button'
4
4
  import { FcGoogle } from "react-icons/fc";
5
5
  import React from 'react'
6
- import { authClient } from "../../lib/auth-client";
7
- import { LOGIN_REFERRER_COOKIE } from "../../lib/cookie-names";
6
+ import { authClient } from "../../../lib/auth/client";
7
+ import { LOGIN_REFERRER_COOKIE } from "../../../lib/security/cookie-names";
8
8
  import { toast } from 'sonner'
9
9
 
10
10
  type Props = {
@@ -2,11 +2,11 @@
2
2
 
3
3
  import React, { useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
- import { Button } from '../ui/button'
6
- import { Input } from '../ui/input'
7
- import { Label } from '../ui/label'
8
- import { Checkbox } from '../ui/checkbox'
9
- import { authClient } from '../../lib/auth-client'
5
+ import { Button } from '../../ui/button'
6
+ import { Input } from '../../ui/input'
7
+ import { Label } from '../../ui/label'
8
+ import { Checkbox } from '../../ui/checkbox'
9
+ import { authClient } from '../../../lib/auth/client'
10
10
  import { toast } from 'sonner'
11
11
 
12
12
  type Props = {
@@ -1,10 +1,10 @@
1
1
  'use client'
2
2
 
3
3
  import React, { useState } from 'react'
4
- import { Button } from '../ui/button'
5
- import { Input } from '../ui/input'
6
- import { Label } from '../ui/label'
7
- import { authClient } from '../../lib/auth-client'
4
+ import { Button } from '../../ui/button'
5
+ import { Input } from '../../ui/input'
6
+ import { Label } from '../../ui/label'
7
+ import { authClient } from '../../../lib/auth/client'
8
8
  import { toast } from 'sonner'
9
9
 
10
10
  const ForgotPasswordForm = () => {
@@ -2,10 +2,10 @@
2
2
 
3
3
  import React, { useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
- import { Button } from '../ui/button'
6
- import { PasswordInput } from '../ui/password-input'
7
- import { Label } from '../ui/label'
8
- import { authClient } from '../../lib/auth-client'
5
+ import { Button } from '../../ui/button'
6
+ import { PasswordInput } from '../../ui/password-input'
7
+ import { Label } from '../../ui/label'
8
+ import { authClient } from '../../../lib/auth/client'
9
9
  import { toast } from 'sonner'
10
10
 
11
11
  type Props = {
@@ -1,9 +1,9 @@
1
1
  'use client'
2
2
 
3
3
  import { useEffect } from 'react'
4
- import { useSession } from '../../lib/auth-client'
5
- import { clearStoredVisitorId, getDeviceSignals, getStoredVisitorId, getVisitorId } from '../../lib/device-fingerprint'
6
- import { useConsentFor, useCookieConsent } from '../../lib/cookie-consent'
4
+ import { useSession } from '../../../lib/auth/client'
5
+ import { clearStoredVisitorId, getDeviceSignals, getStoredVisitorId, getVisitorId } from '../../../lib/security/device-fingerprint'
6
+ import { useConsentFor, useCookieConsent } from '../../../lib/security/cookie-consent'
7
7
 
8
8
  // Mount once (e.g. in the root layout). When a session is present it computes
9
9
  // a FingerprintJS device id and hands it to /api/device-check, which emails
@@ -1,8 +1,8 @@
1
1
  'use client'
2
2
 
3
3
  import React from 'react'
4
- import { authClient } from "../../lib/auth-client";
5
- import { Button } from '../ui/button';
4
+ import { authClient } from "../../../lib/auth/client";
5
+ import { Button } from '../../ui/button';
6
6
 
7
7
 
8
8
  const LogoutButtons = () => {
@@ -1,5 +1,5 @@
1
1
  import { getActivityLogsFiltered } from "@xk2800/nextjs-template/activity/queries"
2
- import AdminActivityLogsTable from "./adminActivityLogsTable"
2
+ import AdminActivityLogsTable from "./admin-activity-logs-table"
3
3
 
4
4
  export default async function ActivityLogsSection() {
5
5
  const { logs, total, page, limit, pages } = await getActivityLogsFiltered({ page: 1, limit: 20 })
@@ -0,0 +1,375 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useRef, useState } from 'react'
4
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../../ui/card'
5
+ import { Button } from '../../../ui/button'
6
+ import { Input } from '../../../ui/input'
7
+ import { Badge } from '../../../ui/badge'
8
+ import { Switch } from '../../../ui/switch'
9
+ import { Label } from '../../../ui/label'
10
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../../ui/select'
11
+ import { DatePickerWithPresets } from '../../../ui/date-picker-with-presets'
12
+ import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '../../../ui/sheet'
13
+ import AuditSeverityBadge, { SeverityLegend } from './audit-severity-badge'
14
+ import { CATEGORY_LABELS, SEVERITY_LABELS, categoryOf } from '../../../../lib/security/activity-severity'
15
+ import { format, subDays } from 'date-fns'
16
+ import { Skeleton } from '../../../ui/skeleton'
17
+ import { DataTable, DataTablePagination, type Column } from '../../../ui/data-table'
18
+ import { toast } from 'sonner'
19
+ import { formatDateTime } from '@xk2800/nextjs-template/lib/formatters'
20
+ import { Download } from 'lucide-react'
21
+
22
+ interface ActivityLog {
23
+ id: string
24
+ action: string
25
+ description: string
26
+ ipAddress: string | null
27
+ userAgent: string | null
28
+ metadata: string | null
29
+ createdAt: Date | string
30
+ userId: string
31
+ userName: string | null
32
+ userEmail: string | null
33
+ }
34
+
35
+ interface PaginationData {
36
+ page: number
37
+ limit: number
38
+ total: number
39
+ pages: number
40
+ }
41
+
42
+ const toYmd = (d: Date) => format(d, 'yyyy-MM-dd')
43
+
44
+ const RANGE_PRESETS = [
45
+ { value: 'any', label: 'Any time' },
46
+ { value: 'today', label: 'Today' },
47
+ { value: '7d', label: 'Last 7 days' },
48
+ { value: '30d', label: 'Last 30 days' },
49
+ { value: 'custom', label: 'Custom range' },
50
+ ]
51
+
52
+ function parseMetadata(raw: string | null) {
53
+ if (!raw) return null
54
+ try {
55
+ return JSON.stringify(JSON.parse(raw), null, 2)
56
+ } catch {
57
+ return raw
58
+ }
59
+ }
60
+
61
+ interface AdminActivityLogsTableProps {
62
+ initialLogs: ActivityLog[]
63
+ initialPagination: PaginationData
64
+ }
65
+
66
+ const makeColumns = (onView: (log: ActivityLog) => void): Column<ActivityLog>[] => [
67
+ {
68
+ name: 'severity',
69
+ title: 'Severity',
70
+ sticky: true,
71
+ minWidth: 100,
72
+ renderer: (log) => <AuditSeverityBadge action={log.action} />,
73
+ },
74
+ {
75
+ name: 'createdAt',
76
+ title: 'Time',
77
+ priority: 0,
78
+ renderer: (log) => (
79
+ <span className="text-sm text-gray-600 dark:text-gray-400">{formatDateTime(log.createdAt)}</span>
80
+ ),
81
+ },
82
+ {
83
+ name: 'user',
84
+ title: 'Actor',
85
+ priority: -1,
86
+ minWidth: 240,
87
+ renderer: (log) => (
88
+ <div className="text-sm">
89
+ <div className="font-medium">{log.userName || 'N/A'}</div>
90
+ <div className="text-xs text-gray-500">{log.userEmail}</div>
91
+ </div>
92
+ ),
93
+ },
94
+ {
95
+ name: 'action',
96
+ title: 'Event',
97
+ minWidth: 160,
98
+ renderer: (log) => (
99
+ <div className="text-sm">
100
+ <div className="font-medium capitalize">{log.action.replace(/_/g, ' ')}</div>
101
+ <div className="max-w-xs truncate text-xs text-gray-500">{log.description}</div>
102
+ </div>
103
+ ),
104
+ },
105
+ {
106
+ name: 'ipAddress',
107
+ title: 'IP Address',
108
+ renderer: (log) => <span className="text-sm font-mono">{log.ipAddress || 'N/A'}</span>,
109
+ },
110
+ {
111
+ name: 'details',
112
+ title: '',
113
+ minWidth: 80,
114
+ renderer: (log) => (
115
+ <Button variant="ghost" size="sm" onClick={() => onView(log)}>View</Button>
116
+ ),
117
+ },
118
+ ]
119
+
120
+ export default function AdminActivityLogsTable({ initialLogs, initialPagination }: AdminActivityLogsTableProps) {
121
+ const [logs, setLogs] = useState<ActivityLog[]>(initialLogs)
122
+ const [loading, setLoading] = useState(false)
123
+ const [search, setSearch] = useState('')
124
+ const [category, setCategory] = useState('all')
125
+ const [severity, setSeverity] = useState('all')
126
+ const [range, setRange] = useState('any')
127
+ const [live, setLive] = useState(false)
128
+ const [selected, setSelected] = useState<ActivityLog | null>(null)
129
+ const [dateFrom, setDateFrom] = useState('')
130
+ const [dateTo, setDateTo] = useState('')
131
+ const [page, setPage] = useState(1)
132
+ const [pagination, setPagination] = useState<PaginationData | null>(initialPagination)
133
+ const [isExporting, setIsExporting] = useState(false)
134
+
135
+ const requestId = useRef(0)
136
+
137
+ const filterParams = () => ({
138
+ search,
139
+ ...(category !== 'all' && { category }),
140
+ ...(severity !== 'all' && { severity }),
141
+ ...(dateFrom && { dateFrom }),
142
+ ...(dateTo && { dateTo }),
143
+ })
144
+
145
+ const applyRange = (value: string) => {
146
+ setRange(value)
147
+ const today = new Date()
148
+ if (value === 'today') { setDateFrom(toYmd(today)); setDateTo(toYmd(today)) }
149
+ else if (value === '7d') { setDateFrom(toYmd(subDays(today, 6))); setDateTo(toYmd(today)) }
150
+ else if (value === '30d') { setDateFrom(toYmd(subDays(today, 29))); setDateTo(toYmd(today)) }
151
+ else if (value === 'any') { setDateFrom(''); setDateTo('') }
152
+ }
153
+
154
+ const fetchLogs = async (pageNum: number, silent = false) => {
155
+ const currentRequest = ++requestId.current
156
+ if (!silent) setLoading(true)
157
+ try {
158
+ const params = new URLSearchParams({
159
+ page: pageNum.toString(),
160
+ limit: '20',
161
+ ...filterParams(),
162
+ })
163
+ const response = await fetch(`/api/admin/activity-logs?${params}`)
164
+ if (!response.ok) throw new Error('Failed to fetch activity logs')
165
+ const data = await response.json()
166
+ if (currentRequest !== requestId.current) return
167
+ setLogs(data.logs)
168
+ setPagination(data.pagination)
169
+ } catch (error) {
170
+ if (currentRequest !== requestId.current) return
171
+ if (!silent) toast.error('Failed to load activity logs')
172
+ console.error(error)
173
+ } finally {
174
+ if (currentRequest === requestId.current) setLoading(false)
175
+ }
176
+ }
177
+
178
+ const isFirstRender = useRef(true)
179
+
180
+ useEffect(() => {
181
+ if (isFirstRender.current) {
182
+ isFirstRender.current = false
183
+ return
184
+ }
185
+ const timer = setTimeout(() => {
186
+ fetchLogs(1)
187
+ setPage(1)
188
+ }, 300)
189
+ return () => clearTimeout(timer)
190
+ // eslint-disable-next-line react-hooks/exhaustive-deps
191
+ }, [search, category, severity, dateFrom, dateTo])
192
+
193
+ // Live feed: quiet refetch of the current page every 10s.
194
+ useEffect(() => {
195
+ if (!live) return
196
+ const t = setInterval(() => fetchLogs(page, true), 10_000)
197
+ return () => clearInterval(t)
198
+ // eslint-disable-next-line react-hooks/exhaustive-deps
199
+ }, [live, page, search, category, severity, dateFrom, dateTo])
200
+
201
+ const resetFilters = () => {
202
+ setSearch('')
203
+ setCategory('all')
204
+ setSeverity('all')
205
+ setRange('any')
206
+ setDateFrom('')
207
+ setDateTo('')
208
+ }
209
+
210
+ const handleExport = async () => {
211
+ setIsExporting(true)
212
+ try {
213
+ const params = new URLSearchParams(filterParams())
214
+ const response = await fetch(`/api/admin/activity-logs/export?${params}`)
215
+ if (!response.ok) throw new Error('Failed to export activity logs')
216
+ const blob = await response.blob()
217
+ const url = URL.createObjectURL(blob)
218
+ const link = document.createElement('a')
219
+ link.href = url
220
+ link.download = `activity-logs-${new Date().toISOString().slice(0, 10)}.csv`
221
+ document.body.appendChild(link)
222
+ link.click()
223
+ link.remove()
224
+ URL.revokeObjectURL(url)
225
+ } catch (error) {
226
+ toast.error('Failed to export activity logs')
227
+ console.error(error)
228
+ } finally {
229
+ setIsExporting(false)
230
+ }
231
+ }
232
+
233
+ const hasFilters = !!(search || category !== 'all' || severity !== 'all' || dateFrom || dateTo)
234
+ const columns = makeColumns(setSelected)
235
+ const metadata = selected ? parseMetadata(selected.metadata) : null
236
+
237
+ return (
238
+ <>
239
+ <Card>
240
+ <CardHeader className="space-y-4">
241
+ <div className="flex flex-row items-start justify-between gap-4">
242
+ <div>
243
+ <CardTitle>Activity Events</CardTitle>
244
+ <CardDescription>
245
+ {pagination ? `Showing ${logs.length} of ${pagination.total} events` : 'Loading...'}
246
+ </CardDescription>
247
+ </div>
248
+ <div className="flex items-center gap-4">
249
+ <div className="flex items-center gap-2">
250
+ <Switch id="live-feed" checked={live} onCheckedChange={setLive} />
251
+ <Label htmlFor="live-feed" className="text-sm">Live feed</Label>
252
+ </div>
253
+ <Button variant="outline" size="sm" onClick={handleExport} disabled={isExporting || logs.length === 0}>
254
+ <Download />
255
+ {isExporting ? 'Exporting...' : 'Export CSV'}
256
+ </Button>
257
+ </div>
258
+ </div>
259
+ <div className="flex flex-wrap items-center gap-2">
260
+ <Input
261
+ placeholder="Search user or IP..."
262
+ value={search}
263
+ onChange={(e) => setSearch(e.target.value)}
264
+ className="max-w-xs"
265
+ />
266
+ <Select value={category} onValueChange={setCategory}>
267
+ <SelectTrigger className="w-[170px]"><SelectValue /></SelectTrigger>
268
+ <SelectContent>
269
+ <SelectItem value="all">Category: All</SelectItem>
270
+ {Object.entries(CATEGORY_LABELS).map(([v, l]) => <SelectItem key={v} value={v}>{l}</SelectItem>)}
271
+ </SelectContent>
272
+ </Select>
273
+ <Select value={severity} onValueChange={setSeverity}>
274
+ <SelectTrigger className="w-[150px]"><SelectValue /></SelectTrigger>
275
+ <SelectContent>
276
+ <SelectItem value="all">Severity: All</SelectItem>
277
+ {Object.entries(SEVERITY_LABELS).map(([v, l]) => <SelectItem key={v} value={v}>{l}</SelectItem>)}
278
+ </SelectContent>
279
+ </Select>
280
+ <SeverityLegend />
281
+ <Select value={range} onValueChange={applyRange}>
282
+ <SelectTrigger className="w-[150px]"><SelectValue /></SelectTrigger>
283
+ <SelectContent>
284
+ {RANGE_PRESETS.map((p) => <SelectItem key={p.value} value={p.value}>{p.label}</SelectItem>)}
285
+ </SelectContent>
286
+ </Select>
287
+ {range === 'custom' && (
288
+ <>
289
+ <DatePickerWithPresets
290
+ placeholder="From"
291
+ date={dateFrom ? new Date(`${dateFrom}T00:00:00`) : undefined}
292
+ onDateChange={(d) => setDateFrom(d ? toYmd(d) : '')}
293
+ disableFutureDates
294
+ />
295
+ <DatePickerWithPresets
296
+ placeholder="To"
297
+ date={dateTo ? new Date(`${dateTo}T00:00:00`) : undefined}
298
+ onDateChange={(d) => setDateTo(d ? toYmd(d) : '')}
299
+ disableFutureDates
300
+ />
301
+ </>
302
+ )}
303
+ {hasFilters && (
304
+ <Button variant="ghost" size="sm" onClick={resetFilters}>Clear</Button>
305
+ )}
306
+ </div>
307
+ </CardHeader>
308
+ <CardContent>
309
+ {loading ? (
310
+ <div className="space-y-4">
311
+ {[...Array(5)].map((_, i) => (
312
+ <Skeleton key={i} className="h-16 w-full" />
313
+ ))}
314
+ </div>
315
+ ) : logs.length === 0 ? (
316
+ <p className="text-center text-gray-500 py-8">No activity logs found</p>
317
+ ) : (
318
+ <DataTable columns={columns} data={logs} getRowId={(log) => log.id} pageSize={false} />
319
+ )}
320
+
321
+ {pagination && (
322
+ <DataTablePagination
323
+ page={page}
324
+ pages={pagination.pages}
325
+ onPageChange={(p) => {
326
+ setPage(p)
327
+ fetchLogs(p)
328
+ }}
329
+ className="mt-6 pt-6"
330
+ />
331
+ )}
332
+ </CardContent>
333
+ </Card>
334
+
335
+ <Sheet open={!!selected} onOpenChange={(o) => !o && setSelected(null)}>
336
+ <SheetContent className="w-full overflow-y-auto sm:max-w-lg">
337
+ {selected && (
338
+ <>
339
+ <SheetHeader>
340
+ <SheetTitle className="capitalize">{selected.action.replace(/_/g, ' ')}</SheetTitle>
341
+ <SheetDescription>{selected.description}</SheetDescription>
342
+ </SheetHeader>
343
+ <dl className="space-y-4 px-4 pb-4 text-sm">
344
+ <div className="flex items-center gap-2">
345
+ <AuditSeverityBadge action={selected.action} />
346
+ <Badge variant="outline">{CATEGORY_LABELS[categoryOf(selected.action)]}</Badge>
347
+ </div>
348
+ {([
349
+ ['Time', formatDateTime(selected.createdAt)],
350
+ ['Actor', `${selected.userName || 'N/A'} (${selected.userEmail || selected.userId})`],
351
+ ['IP address', selected.ipAddress || 'N/A'],
352
+ ['User agent', selected.userAgent || 'N/A'],
353
+ ['Event ID', selected.id],
354
+ ] as const).map(([k, v]) => (
355
+ <div key={k}>
356
+ <dt className="font-medium text-gray-600">{k}</dt>
357
+ <dd className="break-all">{v}</dd>
358
+ </div>
359
+ ))}
360
+ {metadata && (
361
+ <div>
362
+ <dt className="font-medium text-gray-600">Metadata</dt>
363
+ <dd>
364
+ <pre className="mt-1 overflow-x-auto rounded-md bg-muted p-3 text-xs">{metadata}</pre>
365
+ </dd>
366
+ </div>
367
+ )}
368
+ </dl>
369
+ </>
370
+ )}
371
+ </SheetContent>
372
+ </Sheet>
373
+ </>
374
+ )
375
+ }